主页面点击编辑按钮:
edit:function(row){ var dataWrap = new AjaxDataWrap("dataWrap"); dataWrap.setData(dataTable.getRecordByRowNum(row.keyId-1)); var data = dataWrap.toJSONData(); var dataArr = []; dataArr.push(data); var url = $$pageContextPath + "testEnv/editappstoredetail"; $.showModalDialog({url: url, datawrap: dataArr}, '编辑信息', vm.queryList, null, "700", "500", 0); }
调用后台controller服务:"editappstoredetail" 并返回页面
@RequestMapping("/editappstoredetail") public String editappstoredetail(@ModelAttribute("responseData") DataCenter dc, @DataWrap AjaxDataWrap<AppRepository> dataWrap) { dc.setAjaxDataWrap("dataWrap", dataWrap); return "testenv/editappstoredetail.html"; }
在编辑页面 点击确定按钮进行保存:并调用后台接口,保存数据到数据库
saveInfo: function () { //收集数据 var formData = myform.collectData(); myform.validate(function (valid) { if (valid) { $.request({ url: $$pageContextPath + 'testEnv/saveInfo', data: [formData], success: function (response) { var code = response.getParameter("code"); if(code === 0){ HyMessage.success([[#{operation.savedSuccessfully}]]); $.cancel(); }else{ HyMessage.error([[#{mask.save_error}]]); } } }); } }); },
controller层的服务接口: “saveInfo”
@RequestMapping("/saveInfo") @ResponseBody public DataCenter saveInfo(@ModelAttribute("responseData") DataCenter dc, @DataWrap AjaxDataWrap<AppRepository> dataWrap){ AppRepository moduleInfo = dataWrap.getData(); try { repositoryService.saveInfo(moduleInfo); dc.setParameter("code", 0); } catch (Exception e) { dc.setParameter("code", 1); LogUtil.getFrameworkLoger().error("保存信息出错!", e.getMessage()); } return dc; }
service层里处理复杂逻辑:saveInfo()
@Override public AppRepository saveInfo(AppRepository moduleInfo) { if(moduleInfo == null){ return null; } if(moduleInfo.getModuleId() == null){ Long id = SequenceUtil.genEntitySequenceNo(InstanceInfo.class); moduleInfo.setModuleId(id); JPAUtil.create(moduleInfo); }else{ JPAUtil.update(moduleInfo); } return moduleInfo; }