前端map传给后端接收

前端let map = new Map();
map.set(1, 1);
map.set(2, 2);
map.set(3, 3);
//map转obj
let obj= Object.create(null);
for (let[k,v] of map) {
    obj[k] = v;
}
$.ajax({
    url:"",
    type:"POST",
    dataType:'json',
    contentType : 'application/json;charset=utf-8',
    data:JSON.stringify(obj), //obj转json
    success:function (data) {

    }
})后端

@PostMapping("")
public void xxx(@RequestBody Map map){
    System.out.println(map);
}

你可能感兴趣的:(java-web,前端,后端,json)