后台:
@RestController @RequestMapping(value = "/main") public class MainDisk { @Autowired private DiskMapper diskMapper; @RequestMapping (value = "/nodeInfo",method = RequestMethod.POST) public List<Disk> getInfo(@RequestBody Disk disk){ System.out.println("--------------"+ disk.getNodeId()); return new ArrayList<>(); }; }
前台:
var a = {"nodeId":2};
$.ajax({ url:"/main/nodeInfo", data:JSON.stringify(a), contentType: "application/json; charset=utf-8", type:"POST", datatype:"json", success:function(result){ console.log(result); } });
注意: Disk 位一个实体类 属性名,需要和 前台变量a 的key 对应, 还需将a 转化为 JSON 类型, 至于 框架怎么把前台参数a 转化为后台bean的过程,自己看源代码