寫在Vue中的methods爲:
recycle(){
console.log(JSON.stringify(this.list))
$.ajax({
url:"http://10.0.73.199:8080/mui_recycle/recycle",
data:JSON.stringify({list:this.list}),
type:"POST",
dataType:"JSON",
contentType:"application/json;charset=UTF-8",
success:function(){
},error:function(){
}
})
}
其中list的格式爲:
[{"productCode":"出廠編碼","computerName":"設備編號","machineType":"機器型號","userDepartment":"集團信息部","userCode":"19120019","userName":"朱正"}],
後臺接收爲:
@Transactional
@ResponseBody
@RequestMapping("/recycle")
public Map recycle(@RequestBody JSONObject jsonObject, HttpServletRequest request){
Map map = new HashMap();
..........
}
參考:https://blog.csdn.net/qq_22339269/article/details/86180588
另外,對結果進行操作:
JSONArray jsonArray = jsonObject.getJSONArray("list");//得到整個JSON數組 for(int i = 0;i<jsonArray.size();i++){ JSONObject object = jsonArray.getJSONObject(i);//得到數組的每個值 String productCode = object.getString("productCode");//每一組值得每個key對應的值 String wareHouseNo = object.getString("wareHouseNo"); }