springboot接收前台ajax传递的json数组

写在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");
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章