@Controller 和 @RestController的区别
时间: 2023-10-07 07:07:11 浏览: 92
@Controller、@RestController注解区别详解
5星 · 资源好评率100%
@Controller注解标识一个Spring类是Spring MVC controller处理器,它的方法可以通过返回String跳转到模板页面,也可以通过@ResponseBody注解返回实体对象。而@RestController注解是@Controller和@ResponseBody的结合体,它的所有方法只能返回String、Object、Json等实体对象,不能跳转到模板页面。所以,@RestController注解相当于@ResponseBody和@Controller合在一起的作用,用于构建RESTful风格的Web服务。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [@Controller和@RestController的区别?](https://blog.csdn.net/zoujian1991/article/details/119568177)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [@Controller、@RestController注解区别详解](https://download.csdn.net/download/weixin_38670208/12745797)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [@Controller和@RestController的区别](https://blog.csdn.net/qq_41029282/article/details/118326686)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文