文章目录
一、获取总记录条数
接口:
/**
* 获取总记录条数
* @return
*/
Long selectTotal();
mapper.xml:
count(*) count(1)
count(具体的字段):查询的是非空的个数(MySql面试题)
<select id="selectTotal" resultType="long">
select count(*) from t_student
</select>
测试:
@Test
public void testSelectTotal() throws IOException, ParseException {
SqlSession session = SqlSessionUtil.openSession();
StudentMapper mapper = session.getMapper(StudentMapper.class);
Long total = mapper.selectTotal();
System.out.println(total);
session.close();
}
运行结果: