spring boot 使用分页插件pagehelper
一.引入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
二.以查询到的一个list集合为例
@Select("select * from `order` where uId=#{uId}")
@Results({@Result(column="uId",property = "user",
one=@One(select="cn.bongbb.mapper.UserMapper.getUserById")),
@Result(column="gId",property ="good",
one=@One(select="cn.bongbb.mapper.GoodMapper.getGoodById"))})
public List<Order> selectOrderByUId(Integer uId);
public List<Order> selectOrderByUId(Integer uId, Integer pageNum){
PageHelper.startPage(pageNum,10);
List<Order> orders = orderMapper.selectOrderByUId(uId);
return orders;
}
@GetMapping("/user/order/{pageNum}")
public String userOrder(Model model, HttpSession session,
@PathVariable("pageNum") Integer pageNum){
User user = (User)session.getAttribute("user");
List<Order> orders = orderService.selectOrderByUId(user.getuId(),pageNum);
PageInfo<Order> orderPageInfo = new PageInfo<>(orders);
orderPageInfo.setPageNum(pageNum);
model.addAttribute("orders",orders);
model.addAttribute("orderPageInfo",orderPageInfo);
return "user/orderList";
}
<div>
<span>
<a th:href="@{/user/order/1}">首页</a>
</span>
<span>
<a th:href="${orderPageInfo.isIsFirstPage()==true}?
@{/user/order/1}:@{/user/order/}+${orderPageInfo.getPageNum()-1}">上一页</a>
</span>
<span th:text="${orderPageInfo.getPageNum()}+'/'+
${orderPageInfo.getPages()}">
</span>
<span>
<a th:href="${orderPageInfo.isIsLastPage()==true}?
@{/user/order/}+${orderPageInfo.getPages()}:
@{/user/order/}+${orderPageInfo.getPageNum()+1}">下一页
</a>
</span>
<span>
<a th:href="@{/user/order/}+${orderPageInfo.getPages()}">尾页</a>
</span>
</div>
三.效果图