我想通过Ajax传递一个Pojo给Controller,但是controller接收不到数据
下面是Ajax代码片
$.ajax({
url: basePath + "update.action",
method:"post",
dataType:"json",
contentType: "application/json",
data:JSON.stringify({
cookId: $("#edit_cook_id").val,
cookName: $("#edit_cookName").val,
cookFlavor: $("#edit_cookFlavor").val,
cookRepertory: $("#edit_cookRepertory").val,
cookPrice: $("#edit_cookPrice").val,
cookType: $("#edit_cookType").val
}),
success: function (data) {
if (data > "0") {
alert("客户信息更新成功!");
} else {
alert("客户信息更新失败!");
}
window.location.reload();
},
error:function () {
alert("客户信息更新失败! ");
}
});
接下来是Controller
@RequestMapping(value = {"update"} ,method = { RequestMethod.POST })
@ResponseBody
public Long update(@RequestBody CookBook cookBook) {
System.out.println("==============================================");
System.out.println(cookBook);
Long aLong = restaurantService.updateCook(cookBook);
return aLong;
}
这是打印语句
CookBook{cookId=0, cookName='null', cookFlavor='null', cookRepertory=0, cookPrice=0, cookType='null'}
异常是说
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE cook_id
= 0' at line 4
找了一天问题了,苦恼