@RestController
Spring4之后新加入的注解,原来返回JSON需要@ResponseBody和@Controller配合。
即@RestController是@ResponseBody和@Controller的组合注解
@RestController = @Controller + @ResponseBody;
@RestController
public class TestController {
@RequestMapping(value="/hello", method= RequestMethod.GET)
public String hello(){
return "hello";
}
}
与下面的一样:
@Controller
@ResponseBody
public class TestController {
@RequestMapping(value="/hello", method= RequestMethod.GET)
public String hello(){
return "hello";
}
}