1. 程式人生 > >ajax請求介面,後端已經訪問到了,前端報404

ajax請求介面,後端已經訪問到了,前端報404

調介面報錯如下:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Sep 11 16:01:03 CST 2018
There was an unexpected error (type=Not Found, status=404).
No message available

按理說404是路徑不多,導致找不到著,但是後端的介面實際已經訪問到了,但還是報錯!!!
- 前端程式碼:

$.ajax({
                url : '/v1/chooseStock/filter'
, type : 'POST', // async: false, cache: false, // contentType: false, processData: false, data:requestData, dataType : 'json', success : function(data) { console.
log(data);
  • 後端程式碼:
    這裡寫圖片描述

發現沒???我搞了半天才發,是類上邊的註解@Controller導致的,原因就得好好看看@Controller和@RestController了。

@Controller和@RestController區別:
@Controller 是檢視解析器的,即Return返回的是檢視,即jsp或者html頁面的。
如果返回資料json、xml等,需要在對應的方法上加上@ResponseBody註解。

@RestController 是@Controller和@ResponseBody兩個註解的結合,返回json資料不需要在方法前面加@ResponseBody註解了,但使用@RestController這個註解,就不能返回jsp,html頁面,檢視解析器無法解析jsp,html頁面