Index: forgon-tools/src/main/java/com/forgon/tools/json/JSONUtil.java =================================================================== diff -u -r14217 -r14267 --- forgon-tools/src/main/java/com/forgon/tools/json/JSONUtil.java (.../JSONUtil.java) (revision 14217) +++ forgon-tools/src/main/java/com/forgon/tools/json/JSONUtil.java (.../JSONUtil.java) (revision 14267) @@ -291,7 +291,7 @@ JSONObject json = new JSONObject(); addSuccess(json,success); if(StringTools.isNotBlank(message)){ - json.put("message", message); + addMessage(json, message); } return json; } @@ -302,8 +302,27 @@ * @return 原json对象,并且添加了是否成功的标志位 */ public static JSONObject addSuccess(JSONObject json,boolean success){ + return addProperty(json,"success",success); + } + /** + * 在json对象中添加提示消息 + * @param json json对象 + * @param message 消息内容 + * @return 原json对象,并且message属性修改为新的消息内容。如果json为null,返回null + */ + public static JSONObject addMessage(JSONObject json,String message){ + return addProperty(json,"message",message); + } + /** + * 在json对象中添加属性 + * @param json json对象 + * @param name 属性名称 + * @param value 属性值 + * @return 原json对象,并且name属性修改为新的value值。如果json为null,返回null + */ + public static JSONObject addProperty(JSONObject json,String name,Object value){ if(json != null){ - json.put("success", success); + json.put(name, value); } return json; } Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/basedatamanager/sterilizer/action/SterilizerAction.java =================================================================== diff -u -r13416 -r14267 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/basedatamanager/sterilizer/action/SterilizerAction.java (.../SterilizerAction.java) (revision 13416) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/basedatamanager/sterilizer/action/SterilizerAction.java (.../SterilizerAction.java) (revision 14267) @@ -38,7 +38,9 @@ import com.forgon.disinfectsystem.entity.basedatamanager.supplier.Supplier; import com.forgon.disinfectsystem.entity.basedatamanager.supplyroomconfig.SupplyRoomConfig; import com.forgon.tools.StrutsParamUtils; +import com.forgon.tools.StrutsResponseUtils; import com.forgon.tools.hibernate.ObjectDao; +import com.forgon.tools.json.JSONUtil; import com.forgon.tools.json.JsonPropertyFilter; import java.text.SimpleDateFormat; @@ -124,6 +126,7 @@ * 保存Sterilizer */ public String saveSterilizer() { + JSONObject outputJson = JSONUtil.buildJsonObject(false,"保存失败"); try { if (sterilizer != null) { if (StringUtils.isNotBlank(sterilizer.getSupplierID())) { @@ -171,6 +174,10 @@ for (String consumable : consumableArray) { String [] items = consumable.split("#&"); if(items[0].equals("-1")){ + if(items.length <=1){ + JSONUtil.addMessage(outputJson, "请输入耗材名称"); + throw new RuntimeException(); + } ConsumptiveConfig config = new ConsumptiveConfig(); config.setMaterialName(items[1]); consumableConfigList.add(config); @@ -192,6 +199,10 @@ for (String testItem : testItemArray) { String [] items = testItem.split("#&"); if(items[0].equals("-1")){ + if(items.length <=1){ + JSONUtil.addMessage(outputJson, "请输入检测项名称"); + throw new RuntimeException(); + } DetectionItem item = new DetectionItem(); item.setDetectionItemName(items[1]); detectionItemList.add(item); @@ -207,19 +218,13 @@ } sterilizerManager.saveOrUpdate(sterilizer); // 返回条码、供页面打印 - HttpServletResponse httpServletResponse = StrutsParamUtils - .getResponse(); - try { - httpServletResponse.getWriter().print( - "{success:true,barcode:'" + sterilizer.getBarcode() - + "'}"); - } catch (IOException e) { - e.printStackTrace(); - } - + outputJson = JSONUtil.buildJsonObject(true, "保存成功"); + JSONUtil.addProperty(outputJson, "barcode", sterilizer.getBarcode()); + StrutsResponseUtils.output(outputJson); } } catch (Exception e) { e.printStackTrace(); + StrutsResponseUtils.output(outputJson); } return null; }