问题描述
//Service层InsertEntity是自定义的实体,InsList数据库实体orm里的实体publicvoidinsert(InsertEntityinsertEntity){InsListinsList=newInsList();insList.setInsName(insertEntity.getInsName());insList.setInsMade(insertEntity.getInsMade());insList.setInsSeller(insertEntity.getInsSeller());insList.setInsSellPrice(insertEntity.getInsSellPrice());insList.setInsBuyPrice(insertEntity.getInsBuyPrice());this.alldao.getInsListDao().attachDirty(insList);}
publicclassinsertActionextendsBaseAction{privateStringJSONInsert;//页面json传过来的参数publicStringgetJSONInsert(){returnJSONInsert;}publicvoidsetJSONInsert(StringjSONInsert){JSONInsert=jSONInsert;}privateInsertEntityinsertList=newInsertEntity();publicInsertEntitygetInsList(){returninsertList;}publicvoidsetInsList(InsertEntityinsertList){this.insertList=insertList;}publicStringexecute(){try{JSONObjectjson=JSONObject.fromObject(JSONInsert);this.getAllService().getInsertService().insert(insertList);//重点问题就在这里,报错null值求高手解释ServletActionContext.getResponse().setContentType("text/html");ServletActionContext.getResponse().setCharacterEncoding("utf-8");ServletActionContext.getResponse().getWriter().printf(json.toString());ServletActionContext.getResponse().getWriter().flush();ServletActionContext.getResponse().getWriter().close();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnnull;}
//页面ajax提交xml都配置好了functioninsertAction(){varinsName=$("#insName").val();varinsMade=$("#insMade").val();varinsSeller=$("#insSeller").val();varinsBuyPrice=$("#insBuyPrice").val();varinsSellPrice=$("#insSellPrice").val();varJSONInsert=JSON.stringify(newinsertEntity(insName,insMade,insSeller,insBuyPrice,insSellPrice));alert(JSONInsert);$.get("insertAction.action?t="+newDate(),"&JSONInsert="+JSONInsert,function(data){alert(data);});}functioninsertEntity(insName,insMade,insSeller,insBuyPrice,insSellPrice){this.insName=insName;this.insMade=insMade;this.insSeller=insSeller;this.insBuyPrice=insBuyPrice;this.insSellPrice=insSellPrice;}