@getMapping和@postMapping,@RestController 區別


@getMapping和@postMapping,@RestController

 

@RequestMapping   和  @GetMapping @PostMapping 區別

 

@GetMapping是一個組合注解,是@RequestMapping(method = RequestMethod.GET)的縮寫。

 

@PostMapping是一個組合注解,是@RequestMapping(method = RequestMethod.POST)的縮寫。

 

@Controller和@RestController的區別?

官方文檔:
@RestController is a stereotype annotation that combines @ResponseBody and @Controller.
意思是:
@RestController注解相當於@ResponseBody + @Controller合在一起的作用。

1)如果只是使用@RestController注解Controller,則Controller中的方法無法返回jsp頁面,配置的視圖解析器InternalResourceViewResolver不起作用,返回的內容就是Return 里的內容。

例如:本來應該到success.jsp頁面的,則其顯示success.

 

2)如果需要返回到指定頁面,則需要用 @Controller配合視圖解析器InternalResourceViewResolver才行。
3)如果需要返回JSON,XML或自定義mediaType內容到頁面,則需要在對應的方法上加上@ResponseBody注解

和你一起追求代碼的提供給我們的快樂
 
分類:  框架


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM