1、在AlipayForm中添加一个变量index
private Integer index = 0;
2、在页面order.html中加入用于显示分页的代码
<ul class="pagination fr">
<li><a href="order?index=0">«第一页</a></li>
<li th:each="pages,sts:${pagesList}" th:class="${alipayForm.index==sts.index}?'active':''"> <a th:href="@{order(index=${sts.index})}" th:text="${pages}">1</a></li>
<li><a th:href="@{order(index=${pagesList.size()}-1)}">最后一页»</a></li>
</ul>
3、在CartController中
model.addAttribute("pagesList", cartService.searchOrderListCount(cartForm));
model.addAttribute("orderList", cartService.searchOrderList(cartForm, alipayForm.getIndex()));
4、 在CartService中
public List<Integer> searchOrderListCount(CartForm frm) {
Double count = queryDao.executeForObject("Cart.selectAlipayHistoryListCount", frm, Double.class);
List<Integer> list = new ArrayList<>();
Integer pages = (int) Math.ceil(count/5);
for (int i=1; i<=pages; i++) {
list.add(i);
}
return list; list表示总共有多少页
}
public List<AlipayForm> searchOrderList(CartForm frm, Integer index) {
List<AlipayForm> result = queryDao.executeForObjectList("Cart.selectAlipayHistoryList", frm, index*5, 5);
return result; 根据不同的区间来查询信息(index*5, 5)每页5条记录
}
5、在CartSqlMap中
<select id="selectAlipayHistoryListCount" parameterClass="cn.agriculture.web.form.CartForm"
resultClass="java.lang.Double">
SELECT count(0) 查询表中记录的行数
FROM alipay_history
WHERE commodity_id is null
AND guest_id = #guestId#
ORDER BY update_time DESC
</select>