转自:https://blog.csdn.net/u010412719/article/details/69710480
Spring4之后新加入的注解,原来返回json需要@ResponseBody和@Controller配合。
即@RestController是@ResponseBody和@Controller的组合注解。
1 @RestController 2 public class HelloController { 3 @RequestMapping(value="/hello",method= RequestMethod.GET) 4 public String sayHello(){ 5 return "hello"; 6 } 7 }
与下面的代码作用一样
1 @Controller 2 @ResponseBody 3 public class HelloController { 4 @RequestMapping(value="/hello",method= RequestMethod.GET) 5 public String sayHello(){ 6 return "hello"; 7 } 8 }