@RestController註解相當於@ResponseBody + @Controller合在一起的作用。
1) 如果只是使用@RestController註解Controller,則Controller中的方法無法返回jsp頁面,或者html,配置的視圖解析器 InternalResourceViewResolver不起作用,返回的內容就是Return 裏的內容。
2) 如果需要返回到指定頁面,則需要用 @Controller配合視圖解析器InternalResourceViewResolver才行。
如果需要返回JSON,XML或自定義mediaType內容到頁面,則需要在對應的方法上加上@ResponseBody註解。
@RestController註解,相當於@Controller+@ResponseBody兩個註解的結合,返回json數據不需要在方法前面加 @ResponseBody註解了,但使用@RestController這個註解,就不能返回jsp,html頁面,視圖解析器無法解析jsp,html頁面