页面传入json数组参数的处理代码
如:[{name:”张三”,value:”1″},{name:”李四”,value:”1″},{name:”王五”,value:”1″}]
思路:先在前段转化为string,然后把后台接收到的string转为list,这里要用到json的jar包
前段传送代码:
/** * 添加标签 * @returns */ addLabels:function(){ var obj = { labelsListAdd: JSON.stringify(tagManagerment.defaultOption.labelsListAdd) }; commonAjax.ajaxSubmit("label/addLabels.do",obj,function(result){ if(result.resCode == 0){ layer.alert("添加成功!",function(){ location.reload(); }); }else{ layer.msg("未知错误,修复中") } }); },
后台接受代码
@Override public ResultVO addLables(Map<String, String> map) throws Exception { log.info(GlobalContract.LOG_BEGIN); String list=map.get("labelsListAdd"); //把字符串转成list List<LabelDto> labelsList=new ArrayList<LabelDto>(); JSONArray jsonList = JSONArray.fromObject(list); LabelDto labelDto=null; for(int i=0;i<jsonList.size();i++){ labelDto=new LabelDto(); LabelVO labelVO = (LabelVO)JSONObject.toBean(jsonList.getJSONObject(i),LabelVO.class); labelDto.setCreatorId(Integer.parseInt(labelVO.getCreatorId())); labelDto.setLabel_id(Integer.parseInt(labelVO.getValue())); labelDto.setLabel_name(labelVO.getTypeDesc()); labelDto.setStore_id(Integer.parseInt(labelVO.getStore_id())); labelDto.setSource_type(labelVO.getSource_type()); labelsList.add(labelDto); } labelDao.addLabels(labelsList); ResultVO resultVO =new ResultVO(); log.info(GlobalContract.LOG_END); return resultVO; }
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/13904.html