@RestController 包含的注解
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {
String value() default "";
}
使用 @ResponseBody注解的方法返回的数据格式是json串
@RestController = @Controller + @ResponseBody
举例
@RestController public class JsonController { @GetMapping(value = "/hello") public List<UserVo> hello() { List<UserVo> list = new ArrayList<>(); list.add(new UserVo("周一",10)); list.add(new UserVo("周二",20)); return list; }
// 无用注解 @GetMapping(value = "/hello2") public @ResponseBody List<UserVo> hello2() { List<UserVo> list = new ArrayList<>(); list.add(new UserVo("四",10)); list.add(new UserVo("三",20)); return list; } }
[{"name":"四","age":10},{"name":"三","age":20}]