the front end writes an ajax
<script>
test.onclick=function () {
var user = {
"productId":1000,
"productQuantity":1
};
alert(11);
$.ajax({
type: "POST",
dataType:"json",
async:"true",
contentType: "application/json",
url: "/campus_ordering_system/master/buycar/list",
data: JSON.stringify(user) ,
success:function(data){
//TODO
alert(1);
},
error:function () {
alert(user.productId);
alert(2);
}
})
}
</script>
here, you can get the user object with string, but it comes out as a string of {"productId": 1000, "productQuantity": 1}. If you change it to JSONObject, the received value is null
. @RequestMapping("/list")
@ResponseBody
public ModelAndView list(HttpServletRequest request,@RequestBody String params){
HttpSession session=request.getSession();
System.out.println(":"+params);
System.out.println(":"+request.getParameter("productId"));
ProductInfo productInfo=productInfoService.findByOneProductInfo("1000");
session.setAttribute("data",productInfo);
return new ModelAndView("buycar/buycar");
}