@RestController 与 @Controller的区别
时间: 2023-08-26 12:17:16 浏览: 93
@RestController和@Controller注解的区别1
@RestController和@Controller是Spring框架中用于处理HTTP请求的注解。它们有以下区别:
1. 功能不同:@RestController注解相当于@ResponseBody和@Controller的结合体,用于返回JSON、XML或自定义mediaType类型的数据到页面。而@Controller注解用于返回视图,可以返回jsp页面或html。
2. 特殊处理:当使用@RestController注解标记的Controller类时,视图解析器InternalResourceViewResolver不起作用,返回的内容是方法中的返回值。而使用@Controller注解时,可以返回指定的页面。
综上所述,@RestController注解适用于返回JSON、XML或自定义mediaType类型的数据,而@Controller注解适用于返回视图。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [@RestController和@Controller的区别](https://blog.csdn.net/u010533180/article/details/129293701)[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^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [@RestController注解和@Controller注解](https://blog.csdn.net/qq_42447107/article/details/115628778)[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^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [@Controller和@RestController的区别?](https://blog.csdn.net/m0_37948977/article/details/100580448)[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^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文