码迷,mamicode.com
首页 > 其他好文 > 详细

8-17 页面分页

时间:2015-08-17 17:37:04      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

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.java中,添加下列代码

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

4、 在CartService.java中

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.xml中

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


8-17 页面分页

标签:

原文地址:http://my.oschina.net/u/2411782/blog/493536

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!