本文共 1593 字,大约阅读时间需要 5 分钟。
尊重个人劳动成果,转载请注明出处:
StudentMapper.xml 代码:
提示:limit #{start},#{size}
中的 start,size 都是 map 集合的 key ,不是 value。
java 关键代码:
@Testpublic void main() throws Exception { StudentDao studentDao = new StudentDao(); // 输出无条件分页查询结果 System.out.println(studentDao.testFindByFY(0, 3)); System.out.println(studentDao.testFindByFY(3, 3)); System.out.println(studentDao.testFindByFY(6, 3));}// 无条件分页查询public ListtestFindByFY(int start, int size) throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(); Map map = new LinkedHashMap (); map.put("start", start); map.put("size", size); return sqlSession.selectList(nameSpace + ".findByFY", map);}
输出结果:
StudentMapper.xml 代码:
java 关键代码:
@Testpublic void main() throws Exception { StudentDao studentDao = new StudentDao();// 输出有条件分页查询结果 System.out.println(studentDao.testFindByFYWithName(0,2,"czd")); System.out.println(studentDao.testFindByFYWithName(2,2,"czd"));}// 有条件分页查询public ListtestFindByFYWithName(int start, int size, String name) throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(); Map map = new LinkedHashMap (); map.put("start", start); map.put("size", size); map.put("name",name); return sqlSession.selectList(nameSpace + ".findByFYWithName", map);}
输出结果: