1. 程式人生 > >SSM分頁、多條件查詢

SSM分頁、多條件查詢

jsp頁面首頁、尾頁、上一頁、下一頁

================================================================================================================

    <c:if test="${empty orderList}">

 <tr><td colspan="10" style="text-align:center"><font color="#3598dc">查無資料</font></td></tr>
</c:if>
<c:if test="${not empty orderList}">
<c:forEach items="${orderList}" var="a" varStatus="status" >
   <tr>
<td style="padding:0 0 0 5px;width:80px;">${ status.index + 1+offset}</td>
<td style="padding:0 0 0 5px;width:100px;">${a.order_id }</td>
<td style="padding:0 0 0 5px;width:100px;">${a.real_name }</td>
<td style="padding:0 0 0 5px;width:100px;">${a.identification }</td>
<td style="padding:0 0 0 5px;width:40px;">
<c:if test="${a.sex==1 }">男</c:if>
                <c:if test="${a.sex==2 }">女</c:if>
                <c:if test="${a.sex==3 }">不確定</c:if></td>
                <td style="padding:0 0 0 5px;width:130px;">${a.phone_num }</td>
                <td style="padding:0 0 0 5px;width:230px;"><fmt:formatDate value="${a.upd_ymdhms}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td style="padding:0 0 0 5px;width:80px;">
                <c:if test="${a.status==1 }"> 等待支付</c:if>
                <c:if test="${a.status==2 }"> 已取消</c:if>
                <c:if test="${a.status==3 }"> 支付完成</c:if></td>
<td style="padding:0 0 0 5px;width:100px;">${a.sysuser_name }</td>
<td style="padding:0 0 0 5px;width:170px;">
<a href="SearchOrderByOrderId.action?orderId=${a.order_id }">
<span class="handle" id="see_order">檢視</span></a>&nbsp;

<c:if test="${a.status==1 }">|&nbsp;

<a href="UpdateOrderStatus.action?orderId=${a.order_id }"><span class="handle">取消</span></a>&nbsp;</c:if>|&nbsp;

<a href="UpdateOrderUp.action?orderId=${a.order_id }"><span class="handle" id="edi_order">編輯</span></a></td>

   </tr>
   </c:forEach>

   </c:if>

controller部分程式碼

================================================================================================================


List<OrderCustomerSysuser> ocslist = orderService.findOrderCustomerSysuser(sysuserId,offset, pagesize, real_name,phone_num, order_id);

int count = orderService.selectCountToOrderCustomSysuser(sysuserId,real_name, phone_num, order_id);
int pageTemp=10;

                //pageCount 為頁數
int pageCount = count%pageTemp==0?count/pageTemp:count/pageTemp+1;

                //當前是第幾頁
int currentPage = offset / pagesize + 1;

ModelAndView modelAndView = new ModelAndView();

modelAndView.addObject("orderList", ocslist);
modelAndView.addObject("phone_num", phone_num);
modelAndView.addObject("order_id", order_id);
modelAndView.addObject("real_name", real_name);

                modelAndView.addObject("offset", offset);//從第幾條開始查詢
modelAndView.addObject("pagesize", pagesize);//每頁顯示幾條資料
modelAndView.addObject("pageCount", pageCount);//為頁數
modelAndView.addObject("currentPage", currentPage);//當前是第幾頁
modelAndView.addObject("count", count);

// 指定檢視
modelAndView.setViewName("/Order_management.jsp");
return modelAndView;