@Controller與@RestController區別

  • 共同點: 都用來表示Spring某個類的是否能夠接收HTTP請求請求

  • 不一樣點: @Controller標識一個Spring類是Spring MVC controller處理器 @RestController: @RestController是@Controller和@ResponseBody的結合體,兩個標註合併起來的做用。方法

  • 使用時注意:di

  1. @Controller:返回到指定頁面,則須要用 @Controller配合視圖解析器InternalResourceViewResolver才行;
  2. @ResponseBody:4.0以後的版本。若是須要返回JSON,XML或自定義mediaType內容到頁面顯示,須要在對應的方法上加上@ResponseBody註解。
相關文章
相關標籤/搜索