8-17 頁面分頁

一、在AlipayForm中添加一個變量index
html

    private Integer index = 0;java

二、在頁面order.html中加入用於顯示分頁的代碼web

<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>

三、在CartController.java中,添加下列代碼url

model.addAttribute("pagesList", cartService.searchOrderListCount(cartForm));
model.addAttribute("orderList", cartService.searchOrderList(cartForm, alipayForm.getIndex()));

四、 在CartService.java中spa

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條記錄

五、在CartSqlMap.xml中code

<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>
	
<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>
相關文章
相關標籤/搜索