在各个框架下进行分页的方式

本文介绍了在SpringBoot中实现分页的三种方法:使用Hibernate底层的分页、原始的SQL LIMIT语句分页以及利用PageHelper插件进行分页。详细讲解了每种方法的具体实现步骤,包括代码示例和服务、控制器层面的实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.在Springboot中进行分页(底层用的是hiberate)

Sort sort=new Sort(Sort.Direction.DESC,"id");

Pageable pageable1=new pagerequest(start,size,sort);

Page<model> page=daoJpa.findAll(pageable);

二.最原始的分页方式

  就是一个limit语句

 select * from category order by id desc limit #{start},#{count}

三.使用pagehelper进行分页

一.重构之前的pagehelper分页

1.mapper.xml文件中的

<mapper namespace="">

<select id="list" resultType="Category">

   select * from category  order by id desc

</select>

</mapper>

2.mapper接口

List<Category>  list();

3.service就是调用了mapper接口而已

4.controller

  Pagehelper.offsetPage(page.getstart(),page.getcount());

List<Category> cs=categoryService.list();

int total=new PageInfo<>(cs).getTotal();

page.setToatl(total);

然后把page和cs放进model里面

2.重构之后如何使用pagehelper呢

mapper.xml和mapper接口都是系统帮忙实现的。

我们只需要实现service和controller就好了

service

public List<Category> list()

{

    CategoryExample example=new CategoryExample();

     example.seyOrderByClause("id desc");

return CategoryMapper.selectByExample(example);

}

controller中的和重构之前的是一样的,因为重构也只是改变了对数据可的操作

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值