在alipayForm中添加:private Integer index = 0;
在Controller里的order路径下添加如下代码:
@RequestMapping(value = "order", method = RequestMethod.GET)
public String order(Model model, AlipayForm alipayForm, HttpSession session, Device device) {
GoodsForm goodsForm=new GoodsForm();
List<GoodsForm> commodityType = goodsService.getType();
goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId());
model.addAttribute("goodsForm", goodsForm);
model.addAttribute("commodityType", commodityType);
log.info("我的订单");
CartForm cartForm = new CartForm();
model.addAttribute("cartForm", cartForm);
UVO uvo = (UVO)session.getAttribute("UVO");
if (uvo == null || StringUtils.isEmpty(uvo.getGuestId())) {
return "redirect:/initGuestLogin";
}
cartForm.setGuestId(uvo.getGuestId());
model.addAttribute("cartList", cartService.searchCartList(cartForm));
model.addAttribute("pagesList", cartService.searchOrderListCount(cartForm));
model.addAttribute("orderList", cartService.searchOrderList(cartForm, alipayForm.getIndex()));
model.addAttribute("alipayForm", alipayForm);
if(device.isNormal()) {
return "shop/order";
} else {
return "mobile/alipay/replayAlipayConfirm";
}
}
对应的Service里添加相应的方法
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;
}
public List<AlipayForm> searchOrderList(CartForm frm, Integer index) {
List<AlipayForm> result = queryDao.executeForObjectList("Cart.selectAlipayHistoryList", frm, index*5, 5);
return result;
}
SQL文
<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>
<select id="selectAlipayHistoryList" parameterClass="cn.agriculture.web.form.CartForm"
resultClass="cn.agriculture.web.form.AlipayForm">
SELECT out_trade_no as outTradeNo,
subject as subject,
price as price,
body as body,
show_url as showUrl,
receive_name as receiveName,
receive_address as receiveAddress,
receive_zip as receiveZip,
receive_phone as receivePhone,
receive_mobile as receiveMobile,
guest_id as guestId,
update_time as updateTime,
update_user as updateUser,
is_paid as isPaid
FROM alipay_history
WHERE commodity_id is null
AND guest_id = #guestId#
ORDER BY update_time DESC
</select>
页面中的获取
<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>