【spring Boot】Spring中@Controller和@RestController之間的區別


spring Boot入手的第一天,看到例子中的@RestController .............

相同點:都是用來表示Spring某個類的是否可以接收HTTP請求

不同點:@Controller標識一個Spring類是Spring MVC controller處理器

    @RestController:  a convenience annotation that does nothing more than adding the@Controller and @ResponseBody annotations。 

              @RestController是@Controller和@ResponseBody的結合體,兩個標注合並起來的作用。

 

舉例子:

@Controller  
@ResponseBody  
public class MyController { }  
  
@RestController  
public class MyController { } 
@ResponseBody 加載Controller表明整個的Controller中都是返回數據而不是去找相應的頁面地址!!!!


免責聲明!

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



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