博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mybatis 学习记录(2)—— 分页查询
阅读量:2059 次
发布时间:2019-04-29

本文共 1593 字,大约阅读时间需要 5 分钟。

尊重个人劳动成果,转载请注明出处:

1. 无条件分页查询

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 List
testFindByFY(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);}

输出结果:

image

2. 有条件分页查询

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 List
testFindByFYWithName(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);}

输出结果:

image

你可能感兴趣的文章
GridView+存储过程实现'真分页'
查看>>
flask_migrate
查看>>
解决activemq多消费者并发处理
查看>>
UDP连接和TCP连接的异同
查看>>
hibernate 时间段查询
查看>>
java操作cookie 实现两周内自动登录
查看>>
Tomcat 7优化前及优化后的性能对比
查看>>
Java Guava中的函数式编程讲解
查看>>
Eclipse Memory Analyzer 使用技巧
查看>>
tomcat连接超时
查看>>
谈谈编程思想
查看>>
iOS MapKit导航及地理转码辅助类
查看>>
检测iOS的网络可用性并打开网络设置
查看>>
简单封装FMDB操作sqlite的模板
查看>>
iOS开发中Instruments的用法
查看>>
iOS常用宏定义
查看>>
被废弃的dispatch_get_current_queue
查看>>
什么是ActiveRecord
查看>>
有道词典for mac在Mac OS X 10.9不能取词
查看>>
关于“团队建设”的反思
查看>>