还是之前推荐人的那个功能,因为提交了多条件的内容到后台 然后保存至数据库,那么这些数据该如何回显呢?这里就需要使用传入map对象了 具体的ServeltImpl如下:
页面有几个表的数据 可以将每个表查询到的数据都统一放到一个map中 然后将这个map传到页面上,页面会根据map的key名进行拆分,具体的封装见下service层: @Override public Map<String, Object> selectSignsAndEcoupon(String id,LsBsecoupon lb) { LsAcSignm nm = lsAcSignmMapper.selectByIdAndRtype(id); Map<String, Object> param = new HashMap<>(); List<LsBsecoupon> lblist=lsAcRefereedMapper.getECoupons(lb); param.put("lblist", lblist); if(nm!=null){ //Map<String, Object> param = new HashMap<>(); List<LsAcSignd> ndlist = lsAcSigndMapper.selectLsAcSigndBySid(id); param.put("nm", nm); param.put("ndlist", ndlist); return param; } return param; } 这个map中有3个对象,相当于3张表里的数据都放到了这个map中,在前端的话就可以根据这里的key名来做处理 nm lblist ndlist
现在这个map中有了3个对象,然后在controller中通过model对象传到页面中 如下:
model.addAllAttributes(param); return "common/wx/refereeView"; 该param就是服务层传过来的map 调用这个addAllAttributes就可以将map传到页面中 因为本小白比较懒,页面的代码风格可能比较臃肿,很多的css都是自己写到标签中去了 打算后期在归类 总之当时是想先将功能实现出来 下面将展示前端页面的代码部分: <div id="fathers"> <div id="context" class="context" th:if="${not #lists.isEmpty(ndlist)}" th:each="li:${ndlist}"> <div style="background:#fff;width:100%;margin-top:20px;text-align:left;height:170px;padding:10px;border-radius: 5px;"> <div id="person" style="margin-top:10px;"><span>* 推 荐 满</span><span style="font-size:30px;" class="numSub" id="numSub"> - </span><input style="width:150px;text-align:center;border-radius:5px;margin-left:10px;" class="quantity" type="text" th:value="${li.daycount}" readonly="readonly" value="1" id="quantity" size="5" ></input><span style="font-size:20px" class="numAdd" οnclick="numAdd()"> + </span>人<br></br></div> <div id="point" style="margin-top:10px;"><span>* 送 积 分 </span><input type="text" id="pointcount" style="width:150px;margin-left:30px;border-radius:5px" th:value="${li.pointcount}"></input><br></br></div> <div id="isEcoupon" class="isEcoupon" style="margin-top:10px;"><span>*赠 送 优 惠 券 </span><select style="width:150px;border-radius:5px;height:25px" class="isEcoupon"><option value="1" th:selected="${li.isecoupon==1}" selected="selected">赠送</option><option th:selected="${li.isecoupon==0}" value="0">不赠送</option></select></div> <div class="Ecoupon" id="Ecoupon" style="margin-top:10px;"><span>* 优 惠 券 </span> <select name="selectcoupon" id="selectcoupon" style="margin-left:30px;height:25px;width:150px"><br></br> <option th:if="${not #lists.isEmpty(lblist)}" th:each="lb:${lblist}" th:value="${lb.id}" th:text="${lb.cname}" th:selected="${li.cid!=null and li.cid==lb.id}"> </option> <!-- <option th:value="${li.id}" th:text="${li.cname}" th:selected="${li.cid!=null and li.cid==lb.id}"></option> --> </select></div> <div><input type="hidden" id="id" th:value="${li.sid}"></input></div> </div> <br></br> <div style="float:left;margin-left:10px;margin-bottom:30px"> <a class="sub" id="sub" >删除该条件</a> </div> <div style="float:right;margin-right:10px;margin-bottom:30px"> <a class="add" id="add">新增一个条件</a> </div> <div style="clear:both"></div> </div> 这里说明一下 因为我们技术大佬喜欢使用些新奇的技术,例如这里不是使用的jsp,而是html静态页面,但这些数据的传输则使用的th标签,目前api也只有英文版的,想了解的朋友可以去谷歌一下usingthymeleaf.pdf 这是该api的英文文档