ajax传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<String,Object> map){ System.out.println(map); }