Spring boot中@RestController 和@Controller @ResponseBody的关系和使用

我们在SpringBoot集成mybatis的时候,在controller写了方法查询数据库,返回结果的时候,首先需要给类添加一个注解,这个注解,有些博客中的写的是@RestController,有的写的是@Controller,让人傻傻分不清楚,我总结了一下,不知道,对不对,希望有大佬指正
关系:@RestController = @Controller + @ResponseBody

使用场景一

你需要通过浏览器,通过localhost:8080+你定义的接口名,访问到数据直接展示

方式一:

给类上直接使用@RestController
Spring boot中@RestController 和@Controller @ResponseBody的关系和使用
这样通过访问 http://localhost:8081/user/findAll 就可以直接返回数据了
Spring boot中@RestController 和@Controller @ResponseBody的关系和使用

方式二:

在类名上添加注解@Controller 同时在方法上添加 @ResponseBody 也可以实现相同的结果。这里就不展示了。本人亲测

使用场景二

我们在controller中的方法,需要直接放回到一个页面中,经过测试好像只需要在类上添加一个@Controller,然后return中直接返回定义的页面就可以了
Spring boot中@RestController 和@Controller @ResponseBody的关系和使用
总结:也就是说,使用这两个注解的时候,你要确定你是只返回数据,还是需要放回到一个页面,如果只返回数据,你有两种选择方式,1.只在类中添加@RestController 2.在类上添加@Controller + 在方法上添加@ResponseBody
如果需要返回到一个页面,那么你只需要在类上添加@Controller就好了。

以上结论不知道是否正确,希望有大神来指点一下。