小言_互联网的博客

Ajax post请求404

240人阅读  评论(0)


Ajax

$.ajax({
    url:"http://localhost:8080/room/insertHotelCollectionByHotelId",
    contentType:"application/json;charset=UTF-8",
    data:'"hotelCollectionId":"6","hotelId":"3","userId":"3"',
    //注意:上面的data数据缺少{},后台无法解析
    dataType:"json",
    type:"post"
})

原接口

@RequestMapping("insertHotelCollectionByHotelId")
public void insertHotelCollectionByHotelId(@RequestBody String  body) throws IOException {
    System.out.println("insertHotelCollectionByHotelId............");
    System.out.println(body);
}

解决办法:添加@ResponseBody

@ResponseBody
@RequestMapping("insertHotelCollectionByHotelId")
public void insertHotelCollectionByHotelId(@RequestBody String  body) throws IOException {
    System.out.println("insertHotelCollectionByHotelId............");
    System.out.println(body);
}

注意


转载:https://blog.csdn.net/qq_36436290/article/details/101035050
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场