一.在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中的和重构之前的是一样的,因为重构也只是改变了对数据可的操作