注释详解
1. @RestController
官网给出的说明:
This code uses Spring 4’s new @RestController annotation, which marks the class as a controller where every method returns a domain object instead of a view. It’s shorthand for @Controller and @ResponseBody rolled together.
由上可见,@RestController = @Controller + @ResponseBody
@ResponseBody的作用在于告诉控制器返回对象会被自动序列化为JSON,并且传回HttpResponse这个对象。
所以RestController这个注释的作用就是把返回的对象转换为json格式返回前台