报价系统工作总结

    xiaoxiao2021-03-26  5

    关于报价系统的分页实现

    1.分页实现的效果:

    2,首先,在共享文件中定义了属性参数 private int pageindex; //begin:0 private int pagestart; private int pagesize;     然后利用工具生成查询文件.xml <select id="selectClientordersList" parameterType="Clientorders" resultType="Clientorders"> <![CDATA[select * from clientorders]]> <where> fast = 0 <if test="clientorderid != null">and clientorderid = #{clientorderid}</if> <if test="clientid != null">and clientid = #{clientid}</if> <if test="ordercode != null">and ordercode = #{ordercode}</if> <if test="clientname != null">and clientname = #{clientname}</if> <if test="clientcontacts != null">and clientcontacts = #{clientcontacts}</if> <if test="seller != null">and seller = #{seller}</if> <if test="projectname != null">and projectname = #{projectname}</if> <if test="accuracytype != null">and accuracytype = #{accuracytype}</if> <if test="assembly != null">and assembly = #{assembly}</if> <if test="paint != null">and paint = #{paint}</if> <if test="polish != null">and polish = #{polish}</if> <if test="packaged != null">and packaged = #{packaged}</if> <if test="price != null">and price = #{price}</if> <if test="invoicetitle != null">and invoicetitle = #{invoicetitle}</if> <if test="address != null">and address = #{address}</if> <if test="invoice != null">and invoice = #{invoice}</if> <if test="createtime != null">and createtime = #{createtime}</if> <if test="begintime != null">and begintime = #{begintime}</if> <if test="finshtime != null">and finshtime = #{finshtime}</if> <if test="orderstatus != null">and orderstatus = #{orderstatus}</if> <if test="material != null">and material = #{material}</if> <if test="counts != null">and counts = #{counts}</if> <if test="request != null">and request = #{request}</if> <if test="ordermem != null">and ordermem = #{ordermem}</if> </where> <if test="pagesize > 0"> limit ${pagestart} ,${pagesize} </if> </select>注意: <if test="pagesize > 0"> limit ${pagestart} ,${pagesize} </if>是做分页的重要查询语句。 3,在查询方法getClientordersByWorkerid中编辑为: @Override public List<ClientordersBean> getClientordersByWorkerid(ClientordersBean workerid) { ClientordersBean param = new ClientordersBean(); param.setWorkerid(workerid.getWorkerid()); param.setSearchkey(workerid.getSearchkey()); //分页判断 if (workerid.getPagesize()>0){ param.setPagesize(workerid.getPagesize()); param.setPageindex(workerid.getPageindex()); } List<ClientordersBean> list; try{ list = clientordersDao.selectClientordersListByWorkid(param); }catch (Exception e){ e.printStackTrace(); list = new ArrayList<>(); } return list; } 4,然后在controller中对分页进行参数定义: @RequestMapping(value = "/listOrders.act") public String listOrders( //定义参数P为分页页面 @RequestParam(value = "p",required = false,defaultValue = "0") int pageindex, @RequestParam(value = "s",required = false,defaultValue = "") String searchkey, @RequestParam(value = "i",required = false,defaultValue ="-1") int orderstatus){ getRequest().setAttribute("searchkey",searchkey); if(getSessionUserinfo().getType() == 1){ ClientordersBean pageparam=new ClientordersBean(); pageparam.setClientorderid(getSessionUserinfo().getWid()); //设置每一页为25条数据 pageparam.setPagesize(25); pageparam.setPageindex(pageindex); if(orderstatus>-1) { pageparam.setOrderstatus(orderstatus); } if(!searchkey.equals("")){ pageparam.setSearchkey(searchkey); } getRequest().setAttribute("list",ordersManager.getClientordersByWorkerid(pageparam)); }else if(getSessionUserinfo().getType() == 2){ ClientordersBean pageparam=new ClientordersBean(); pageparam.setPagesize(25); pageparam.setPageindex(pageindex); if(orderstatus>-1) { pageparam.setOrderstatus(orderstatus); } if(!searchkey.equals("")){ pageparam.setSearchkey(searchkey); } getRequest().setAttribute("list",ordersManager.getAllClientorders(pageparam)); }else{ List<ClientordersBean> list = new ArrayList<>(); getRequest().setAttribute("list",list); } getRequest().setAttribute("orderStatus",orderstatus); return "crm/orders/orderlist"; } 5,在jsp页面中先写一个获取分页数据的<script>,获取来自listOrders()方法中定义的参数P,并进行参数计算。 <script> <c:choose> <c:when test="${paramValues['p'][0] == null}">var p = 0;</c:when> <c:otherwise>var p = ${paramValues['p'][0]};</c:otherwise> </c:choose> <c:choose> <c:when test="${paramValues['s'][0] != null}">var s = "&s=${paramValues['s'][0]}";</c:when> <c:otherwise>var s = '';</c:otherwise> </c:choose> <c:choose> <c:when test="${paramValues['i'][0] == null}">var i = 0;</c:when> <c:otherwise>var i = ${paramValues['i'][0]};</c:otherwise> </c:choose> function last() { if(p>0){ i = $("#orderStatus").val(); self.location.href = "/crm/listOrders.act?p="+(p-1)+s; } } function next() { i = $("#orderStatus").val(); self.location.href = "/crm/listOrders.act?p="+(p+1)+s; } </script>6,在jsp中定义一个两个Button: <div class="div-line"> <button type="button" <c:if test="${paramValues['p'][0] == null || paramValues['p'][0] > 0}">οnclick="last()"</c:if>>上一页</button> <button type="button" <c:if test="${fn:length(list) == 25}">οnclick="next()"</c:if>>下一页</button> </div> 这样就实现了分页的查询,这里的方法比较难看懂,主要是在前期数据库处理那里用到了工具方法,生成的 <if test="pagesize > 0"> limit ${pagestart} ,${pagesize} </if>语句,这里主要是用于自己的工作总结,和公司的代码匹配,如果看不懂也是正常情况。这样就可以实现简单代码的分页效果啦:

    数据库里面的订单按状态查询:

    实现效果: private Integer orderstatus; // 0:用户询价无下文 1:报价后客户不接受 2:无法满足客户需求无法 3:下单成功 步骤: 1,在controller的方法中定义获取状态的参数: @RequestParam(value = "i",required = false,defaultValue ="-1") int orderstatus @RequestMapping(value = "/listOrders.act") public String listOrders( @RequestParam(value = "p",required = false,defaultValue = "0") int pageindex, @RequestParam(value = "s",required = false,defaultValue = "") String searchkey, @RequestParam(value = "i",required = false,defaultValue ="-1") int orderstatus){ getRequest().setAttribute("searchkey",searchkey); if(getSessionUserinfo().getType() == 1){ ClientordersBean pageparam=new ClientordersBean(); pageparam.setClientorderid(getSessionUserinfo().getWid()); pageparam.setPagesize(25); pageparam.setPageindex(pageindex); if(orderstatus>-1) { pageparam.setOrderstatus(orderstatus); } if(!searchkey.equals("")){ pageparam.setSearchkey(searchkey); } getRequest().setAttribute("list",ordersManager.getClientordersByWorkerid(pageparam)); }else if(getSessionUserinfo().getType() == 2){ ClientordersBean pageparam=new ClientordersBean(); pageparam.setPagesize(25); pageparam.setPageindex(pageindex); //-1为查询全部的订单信息 if(orderstatus>-1) { pageparam.setOrderstatus(orderstatus); } if(!searchkey.equals("")){ pageparam.setSearchkey(searchkey); } getRequest().setAttribute("list",ordersManager.getAllClientorders(pageparam)); }else{ List<ClientordersBean> list = new ArrayList<>(); getRequest().setAttribute("list",list); } //设置键值对,记住分页查询的状态 getRequest().setAttribute("orderStatus",orderstatus); return "crm/orders/orderlist"; } 2,在jsp页面中写<jscrip>获取参数状态和实现按状态查询的分页,以及设置<select>选择后的跳转路径: <script> <c:choose> <c:when test="${paramValues['p'][0] == null}">var p = 0;</c:when> <c:otherwise>var p = ${paramValues['p'][0]};</c:otherwise> </c:choose> <c:choose> <c:when test="${paramValues['s'][0] != null}">var s = "&s=${paramValues['s'][0]}";</c:when> <c:otherwise>var s = '';</c:otherwise> </c:choose> <c:choose> <c:when test="${paramValues['i'][0] == null}">var i = 0;</c:when> <c:otherwise>var i = ${paramValues['i'][0]};</c:otherwise> </c:choose> function last() { if(p>0){ i = $("#orderStatus").val(); self.location.href = "/crm/listOrders.act?p="+(p-1)+s+"&i="+i; } } function next() { i = $("#orderStatus").val(); self.location.href = "/crm/listOrders.act?p="+(p+1)+s+"&i="+i; } function Orderstatuschaxun(sobj) { var status =sobj.options[sobj.selectedIndex].value; if (status != "") { self.location.href = "/crm/listOrders.act?p=0"+s+"&i="+status; sobj.selectedIndex=0; sobj.blur(); } } </script> 3,在jsp增加一个下拉列表,并传值给can参数i,i根据传入的参数做状态查询:  pageparam.setOrderstatus(orderstatus); <select οnchange=Orderstatuschaxun(this) name="select" id="orderStatus" > <option value="" >请选择订单状态查询</option> <option value="-1" <c:if test="${orderStatus == -1}">selected</c:if>>全部</option> <option value="0" <c:if test="${orderStatus == 0}">selected</c:if>>客户询价</option> <option value="1" <c:if test="${orderStatus == 1}">selected</c:if>>交涉中</option> <option value="2" <c:if test="${orderStatus == 2}">selected</c:if>>询价无下文</option> <option value="3" <c:if test="${orderStatus == 3}">selected</c:if>>报价后客户不接受</option> <option value="4" <c:if test="${orderStatus == 4}">selected</c:if>>无法满足客户需求</option> <option value="5" <c:if test="${orderStatus == 5}">selected</c:if>>打印中</option> <option value="6" <c:if test="${orderStatus == 6}">selected</c:if>>打印失败重打</option> <option value="7" <c:if test="${orderStatus == 7}">selected</c:if>>后期处理</option> <option value="8" <c:if test="${orderStatus == 8}">selected</c:if>>发货中</option> <option value="9" <c:if test="${orderStatus == 9}">selected</c:if>>交易完成</option> </select> 这样就实现了按状态进行查询的效果: 关键点在于要在controller中得到状态信息,再根据jsp中传入的参数进行状态分配,然后实现不同的状态查询。

    转载请注明原文地址: https://ju.6miu.com/read-600199.html

    最新回复(0)