前台需要传成组数据且是动态的.拼接成json字符串,ajax传到后台然后解析.
[HTML] 纯文本查看 复制代码 前台拼接json数组后台接受
前台代码 :
function makePicNameJson (){
var picNameListForJson = '{"picNameListForUpload": [';
$(".picInputsArae").children().each(function(){
picNameListForJson += '{"realName":"' + $(this).attr("id") +' ","fileName":"' + $(this).attr("class") +'" },';
});
picNameListForJson = picNameListForJson.substring(0,picNameListForJson.length-1);
picNameListForJson += ']}';
$("#picNameListForJson").attr("value",picNameListForJson);
//alert($("#picNameListForJson").val());
}
后台json读取方式: [Java] 纯文本查看 复制代码 JSONObject.fromObject(picNameListArray.get(i)).get("fileName").toString()
[Java] 纯文本查看 复制代码 后台接受处理 :
以string形式接受
JSONObject picNameListObject = JSONObject.fromObject(picNameListForJson);
JSONArray picNameListArray = picNameListObject.getJSONArray("picNameListForUpload");
for (int i = 0; i < picNameListArray.size(); i++) {
LwApplicateFinishiAddendum lwApplicateFinishiAddendum = new LwApplicateFinishiAddendum();
lwApplicateFinishiAddendum.setProjectId(projectId);
lwApplicateFinishiAddendum.setWorkerId(((UserInfoSS)getUser()).getId());
lwApplicateFinishiAddendum.setPicName(JSONObject.fromObject(picNameListArray.get(i)).get("realName").toString());
lwApplicateFinishiAddendum.setPicSysName(JSONObject.fromObject(picNameListArray.get(i)).get("fileName").toString());
lwApplicateFinishiAddendum.setPid(lwApplicateFinish.getId());
HibernateDAO.save(lwApplicateFinishiAddendum);
}
|