4、SringBoot中的Controller和RestController的区别

结论

简单来说这两的关系是@RestController=@Controller+@ResponseBody

  1. 使用@Controller修饰类,可以根据需要返回各种我们所需的数据(json(方法上使用@ResponseBod),(默认)ModelAndView,静态页面)
  2. 使用RestController修饰类,最后返回结果都会被解析成json字符串,适合所有的方法返回值都是json数据

实验

在这里插入图片描述

在方法上添加@ResponseBody注解,就可以实现@RestController的功能
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_53294821/article/details/114384485
今日推荐