前台把数组对象通过异步传送后台
$.ajax({
url:'${ctx}/reviewIndicatorsAction.do?method=saveById',
type: "POST",
datType: "JSON",
data:{
selections : JSON.stringify(selections)
},
cache: false,
async: false,
success: function(data){
alert(data)
}
});
转化后:JSON.stringify(selections):
[{"mainformid":"9035c7ab-a068-11e8-9a68-000c290a9508","tableId":"eac3e4b9-fcd6-433d-ba4f-119cb20c32d1","uuid":"eac3e4b9-fcd6-433d-ba4f-119cb20c32d1","bdgYear":-1},{"mainformid":"9035c7ab-a068-11e8-9a68-000c290a9508","tableId":"17e8741d-7255-4707-a258-098a69b10f17","uuid":"17e8741d-7255-4707-a258-098a69b10f17","bdgYear":-1}]
后台核心代码获取数组数据:
// 接受参数 String selections = request.getParameter("selections"); logger.info("selections=" + selections); JSONArray json = JSONArray.fromObject(selections); System.out.println("json=" + json); JSONObject jsonOne = null; System.out.println("json.size()=" + json.size()); List<Map<String, String>> list = new ArrayList<>(); for (int i = 0; i < json.size(); i++) { Map<String, String> updataMap = new HashMap<String, String>(); jsonOne = json.getJSONObject(i); System.out.println("jsonOne=" + jsonOne); updataMap.put("mainformid", jsonOne.getString("mainformid")); updataMap.put("tableId", jsonOne.getString("tableId")); updataMap.put("uuid", jsonOne.getString("uuid")); updataMap.put("bdgYear", jsonOne.getString("bdgYear")); list.add(updataMap); } System.out.println("list=" + list);