Spring4之后新加入的注解,原来返回json需要@ResponseBody和@Controller配合。
即@RestController是@ResponseBody和@Controller的组合注解。
代码:
@RestControllerpublic class HelloController { @RequestMapping(value="/hello",method= RequestMethod.GET) public String sayHello(){ return "hello"; }}
@RequestMapping注解提供“路由”信息。 告诉Spring,任何具有路径“/”的HTTP请求都应映射到home方法。
@RestController和@RequestMapping注解是Spring MVC 的注解(它们不是Spring Boot特有的)。