后台用Map<String,String>接:

   @RequestMapping("/save")     public void saveFile(@RequestBody Map<String,String> map){         //map.get("path")         //map.get("content")     }

前台:

var data={"content":"我是数据","path":"我是路径"};             $.ajax({     url: "/tree/save",     type: "post",     contentType: "application/json",     dataType: "json",     data:JSON.stringify(data) 将JSON对象转化为JSON字符串 });

说明:RequestBody接收json字符串。而ajax传的是json对象。

需要用JSON.stringify(data)把对象转为json字符串。

JSON字符串

var data='{"content":"我是数据","path":"我是路径"}';

Json对象

var data={"content":"我是数据","path":"我是路径"};