Mybatis-plugins分页助手实现查询数据分页
生活随笔
收集整理的這篇文章主要介紹了
Mybatis-plugins分页助手实现查询数据分页
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
其他具體代碼接上文-》mybatis自定義處理器
1.導(dǎo)入坐標(biāo)
<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>3.7.5</version></dependency><dependency> <!-- 解析器--><groupId>com.github.jsqlparser</groupId><artifactId>jsqlparser</artifactId><version>0.9.1</version></dependency>2.在UserMapper(dao)接口中定以findAll方法
public List<User> findAll();2.在UserMapper.xml中添加sql查詢
<select id="findAll" resultType="user">select * from user</select>3.測(cè)試
public class MapperTest {@Testpublic void test1() throws IOException {InputStream stream = Resources.getResourceAsStream("SqlMapConfig.xml");SqlSession sqlSession = new SqlSessionFactoryBuilder().build(stream).openSession();UserMapper mapper = sqlSession.getMapper(UserMapper.class);// 設(shè)置分頁(yè)相關(guān)參數(shù)PageHelper.startPage(2,3);List<User> list = mapper.findAll();//獲得與分頁(yè)相關(guān)的參數(shù)PageInfo<User> pageInfo=new PageInfo<User>(list);System.out.println("當(dāng)前頁(yè):"+pageInfo.getPageNum());System.out.println("每頁(yè)顯示條數(shù):"+pageInfo.getPageSize());System.out.println("總條數(shù):"+pageInfo.getTotal());System.out.println("總頁(yè)數(shù):"+pageInfo.getPages());System.out.println("上一頁(yè):"+pageInfo.getPrePage());System.out.println("下一頁(yè):"+pageInfo.getNextPage());System.out.println("是否是第一頁(yè):"+pageInfo.isIsFirstPage());System.out.println("是否是最后一頁(yè):"+pageInfo.isIsLastPage());for(User user:list){System.out.println(user);}} }4.結(jié)果
總結(jié)
以上是生活随笔為你收集整理的Mybatis-plugins分页助手实现查询数据分页的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Mybatis-自定义类型处理器
- 下一篇: Mybatsi注解开发-基础操作