前端传后台出现405,415错误
原因:参数没有序列化就传到后台,后台不认识构造,需要对前端数据包装.
form = {
name: "sennpai",
age: 24,
job: "student",
};
$.ajax({
type:"POST",
data: JSON.stringify(form), //包装
contentType : "application/json;charset=utf-8", //指定ct
url: "xxx",
...
});
后台Controller接收
@RequestMapping(value = "/xxx", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
@ResponseBody
public String getDefectRateCompare(@RequestBody Form form){
}
接收的form
Class Form{
private String name;
private int age;
private String job;
...
//getter and setter
}