1. 首先前台需要寫一個ajax,ajax格式如下:
var json = {"jsonCom":jsonCom,"jsonEsl":jsonEsl}
$.ajax({
url: "/demo/EslController/bing",
type:'post',
data: JSON.stringify(json),
contentType : "application/json;charsetset=UTF-8",
datatype:'json',
success:function (res) {
},
error: function (res) {
alert("執行失敗")
}
})
2. 背景代碼:
@RequestMapping("bing")
public String bing(@RequestBody JSONObject json){
JSONArray jsonCom = (JSONArray)json.get("jsonCom");
JSONArray jsonEsl = (JSONArray)json.get("jsonCom");
return null;
}
JSONArray轉List:
List<Commodity> commodityList = JSONArray.toList(jsonCom,new Commodity(),new JsonConfig());
//第一個參數:jsonarray對象
//第二個參數:List泛型中的對象
//第三個參數:固定
JSONObject 轉實體:
JSONObject conference = (JSONObject)json.get("conference");
String param_json_conference = conference.toString();
ConferenceEntity paserJsonToEntity = conferenceAction.paserJsonToEntity(param_json_conference, ConferenceEntity.class);