码迷,mamicode.com
首页 > 编程语言 > 详细

Spring 的@Controller 和@RestController的区别

时间:2016-12-07 14:12:30      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:继承   ring   作用   ons   res   4.0   方法   control   返回   

@RestController Spring 4.0中新增的特性
@RestController 继承自 @Controller,相当于@ResponseBody + @Controller
 
1.只是使用@RestController时试图解析器不起作用,无法返回页面
例如:返回success.jsp 页面,返回的则是success字符串
 
2.如果要返回页面则使用@Controller
 
3.当使用@Controller时,要返回JSON,则在对应方法上添加@ResponseBody

Spring 的@Controller 和@RestController的区别

标签:继承   ring   作用   ons   res   4.0   方法   control   返回   

原文地址:http://www.cnblogs.com/imeng/p/6140664.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!