ibatis 获取表格条数count(ibatis对于测试、校验数据是个好东西)


校验list好麻烦,校验条数还是比较方便的,也比较有用。


1、定义数据访问接口dao


 public int countAll();

2、创建MyBatis映射文件(UserDaoMapper.xml)mapping

    <select id="countAll" resultType="int">
select count(*) c from user;
select>

3、调用

SqlSession session = factory.openSession();
        User user = new User();
UserDao userDao = session.getMapper(UserDao. class );
System.out.println(
" 记录条数: " + userDao.countAll());



参考http://www.cnblogs.com/wushiqi54719880/archive/2011/07/26/2117601.html

你可能感兴趣的:(mybatis)