=============== MyBatis查询总数 =============== public interface StudentDao { ... // 查询总数 public int cnt(); ... } ... ... public class StudentDaoTest { ... // 测试查询总数 @Test public void testCnt() { try { // SQL会话 SqlSession session = new SqlSessionFactoryBuilder() .build(Resources.getResourceAsStream("mybatis-config.xml")) .openSession(); // 数据访问对象 StudentDao dao = session.getMapper(StudentDao.class); // 查询总数 int cnt = dao.cnt(); // 打印总数 System.out.println(cnt); } catch (IOException e) { e.printStackTrace(); } } ... } 例程:HelloMyBatis