应该还有更简单的方法
但是我不晓得
手动给文本框输入数据保存到数据库
![](https://img2018.cnblogs.com/blog/1665938/201907/1665938-20190705195729640-882716254.png)
A表 :通过订单编号 查询数据获得
B表 :通过A表中的字段查询遍历获得
![](https://img2018.cnblogs.com/blog/1665938/201907/1665938-20190705200256280-1598950600.png)
问题: 手动输入文本框内容 保存到数据库
页面form提交
<form id="forme" action="${pageContext.request.contextPath }/business/businessOfferSubmit" method="post" class="form-horizontal" role="form"> <input type="hidden" name="order_id" value="${businessOffer.order_id }"> <input type="hidden" name="order_status" value="${businessOffer.order_status }"> <div class="widget-body"> <div class="widget-main padding-12 no-padding-left no-padding-right"> <div class="tab-content padding-4">
<div id="businessOfferList" class="tab-pane in active"> <table class="table table-striped table-bordered align-center " > <tr> <td class="tdType">订单编号</td> <td class="tdwidth" >${businessOffer.order_id }</td> <td class="tdType" >业务员</td> <td class="tdwidth">${businessOffer.salesman_name }</td> <td class="tdType">客户</td> <td class="tdwidth">${businessOffer.customer_name }</td> </tr> <tr> <td class="tdType">到达国家</td> <td class="tdwidth">${businessOffer.customer_region }</td> <td class="tdType">收货地址</td> <td class="tdwidth">${businessOffer.take_address }</td> <td class="tdType">收货人</td> <td class="tdwidth">${businessOffer.take_name }</td> </tr> <tr> <td class="tdType">联系电话</td> <td class="tdwidth">${businessOffer.take_phone }</td> <td class="tdType">付款方式</td> <td class="tdwidth">${businessOffer.payment_method }</td> <td class="tdType">货运方式</td> <td class="tdwidth">${businessOffer.take_method }</td> </tr> <tr> <td class="tdType">取件方式</td> <td class="tdwidth">${businessOffer.good_get_method }</td> <td class="tdType">取件费用</td> <td class="tdwidth"><input type="text" class="inputwidth" id="take_charge" name="take_charge">元</td> <td class="tdType" >入库人</td> <td class="tdwidth"><input type="text" class="inputwidth" readonly="readonly"></td> </tr> <tr> <td class="tdType">体积费率</td> <td class="tdwidth"><input type="text" class="inputwidth" id="volume_rate" name="volume_rate">元/方</td> <td class="tdType">重量费率</td> <td class="tdwidth"><input type="text" class="inputwidth" id="weight_rate" name="weight_rate">元/千克</td> <td class="tdType">入库选择</td> <td class="tdwidth">${businessOffer.warehouse_mark }</td> </tr> </table> <table class="table table-striped table-bordered align-center "> <tr class="bolder" > <td>序号</td> <td>货物名称</td> <td>数量</td> <td>单位</td> <td>长(mm)</td> <td>宽(mm)</td> <td>高(mm)</td> <td>核算体积(立方)</td> <td>核算重量(千克)</td> </tr> <c:forEach var="goodById" items="${requestScope.goodById}" varStatus="varStatus"> <tr> <td>${varStatus.count}</td> <td>${goodById.good_name}</td> <td>${goodById.good_count }</td> <td>${goodById.good_unit}</td> <td>${goodById.good_long}</td> <td>${goodById.good_heigth}</td> <td>${goodById.good_width}</td> /*动态生成name 后台可以通过表A 的订单编号查询获得货物清单的序号id*/ <td><input type="text" class="inputwidth" name="a${goodById.good_id}" id="good_volume"></td> <td><input type="text" class="inputwidth" name="b${goodById.good_id}" id="good_weigth"></td> </tr> </c:forEach> </table> </div> <div class="form-group"> <div class="col-sm-5 text-right"> <shiro:hasPermission name="dictionary:edit"> <button type="button" id="myBtn" class="btn btn-primary"> 确 定 </button> </shiro:hasPermission> </div> <div class="col-sm-2 text-right"> <shiro:hasPermission name="dictionary:edit"> <button type="reset" class="btn btn-primary"> 重 置 </button> </shiro:hasPermission> </div> </div> </div> </div> </div> </form>
/*判断 文本框内容*/
<script type="text/javascript"> $("#myBtn").click(function(){ var val1 = $("#volume_rate").val(); var val2 = $("#weight_rate").val(); var val3 = $("#take_charge").val(); var val4 = $("#good_volume").val(); var val5 = $("#good_weigth").val(); if(val1>0&&val2>0&&val3>0&&val4>0&&val5>0){ document.getElementById('forme').submit(); }else { alert("还有未输入的或输入有误"); } });
</script>
|
后台接收
controller层-->service层-->serviceimpl层-->mapper层-->mapperprovider层
@RequestMapping(value="/businessOfferSubmit") public String editBusinessOffer(@RequestParam Map<String, Object> businessOffer,HttpServletRequest req) { LOGGER.debug("编辑业务处理:"+businessOffer); System.out.println(businessOffer); try { Map<String, Object> resultBusinessOffer = businessOfferService.editBusinessOffer(businessOffer); if (resultBusinessOffer!=null) { req.setAttribute("businessOffer_edit_msg", "业务处理成功"); }else { req.setAttribute("businessOffer_edit_msg", "10010-业务处理失败"); } } catch (Exception e) { req.setAttribute("businessOffer_edit_msg", "10009-业务处理更新失败-未知异常"); e.printStackTrace(); } //编辑后跳回到编辑页面 return "forward:/business/toBusinessOfferList/1"; } |
controller层-->service层-->serviceimpl层-->mapper层-->mapperprovider层
/** * 编辑模块 * @param businessOffer * @return */ Map<String, Object> editBusinessOffer(Map<String, Object> businessOffer); |
controller层-->service层-->serviceimpl层-->mapper层-->mapperprovider层
@Override public Map<String, Object> editBusinessOffer(Map<String, Object> businessOffer) {
//将A表输入的数据 更新 数据库 int count= businessOfferMapper.updateForNotNull(businessOffer);
//通过 订单编号 查询 货物清单 List<Map<String,Object>> findGoodById = businessOfferMapper.findGoodById(businessOffer.get("order_id"));
//遍历 查询到的数据 并更新 for (Map<String, Object> map : findGoodById) { Map<String,Object> goods = new HashMap<String, Object>(); // 获取 货物序号 Object good_id=map.get("good_id");
//通过拼接字符串 获得到 页面传回来 的name属性的值 Object good_volume = businessOffer.get("a"+good_id); Object good_weigth = businessOffer.get("b"+good_id); //添加到map中 goods.put("good_id", good_id); goods.put("good_volume", good_volume); goods.put("good_weigth", good_weigth); //前往更新货物清单 int count2= businessOfferMapper.updateGood(goods); } if (count>0) { return businessOffer; } return null; }
|
controller层-->service层-->serviceimpl层-->mapper层-->mapperprovider层
/** * 通过订单编号查询货物清单 * @param businessOfferId * @return */ @Select("SELECT * FROM tb_basic_good WHERE order_id=#{order_id}") List<Map<String, Object>> findGoodById(Object order_id);
/** * 更新订单表的非空字段 * @param user * @return */ @UpdateProvider(type=BusinessOfferProvider.class,method="updateForNotNull") int updateForNotNull(Map<String, Object> businessOffer); /** * 更新货物清单表的非空字段 * @param businessOffer * @return */ @UpdateProvider(type=BusinessOfferProvider.class,method="updateGood") int updateGood(Map<String, Object> businessOffer);
|
controller层-->service层-->serviceimpl层-->mapper层-->mapperprovider层
public String updateForNotNull(Map<String, Object> modular) { //1.构建公共的SQL语句 String sql="UPDATE tb_basic_order SET "; //2.构建SQL动态语句 StringBuilder builder=new StringBuilder(sql); if (modular.get("volume_rate")!=null) { builder.append("volume_rate=#{volume_rate},"); } if (modular.get("weight_rate")!=null) { builder.append("weight_rate=#{weight_rate},"); } if (modular.get("take_charge")!=null) { builder.append("take_charge=#{take_charge},"); } if (modular.get("order_status")!=null) { builder.append("order_status=3,"); } //删除最后一个逗号 builder.delete(builder.length()-1, builder.length()); //追加条件 builder.append(" WHERE order_id=#{order_id}"); //3.返回SQL语句 return builder.toString(); } public String updateGood(Map<String, Object> businessOffer) { //1.构建公共的SQL语句 String sql="UPDATE tb_basic_good SET "; //2.构建SQL动态语句 StringBuilder builder=new StringBuilder(sql); if (businessOffer.get("good_volume")!=null) { builder.append("good_volume=#{good_volume},"); } if (businessOffer.get("good_weigth")!=null) { builder.append("good_weigth=#{good_weigth},"); } //删除最后一个逗号 builder.delete(builder.length()-1, builder.length()); //追加条件 builder.append(" WHERE good_id=#{good_id}"); //3.返回SQL语句 return builder.toString(); } |