springboot常用注解

@RestController,@Controller

 

@RestController中的@AliasFor(annotation = Controller.class)说明@RestController是Controller的一个别名,是一个Controller, @Controller中的@AliasFor(annotation = Component.class)说明@Controller是Component的一个别名,本质上还是一个Component,

再本质一点说,是个Spring bean。因为加了@Component注解之后,表明这是一个逻辑组件,告知Spring要为它创建bean。相当于xml配置文件中的 <bean id="" class=""/>的作用。

@ResponseBody

总结:

@RestController相当于@ResponseBody + @Controller一起作用。

如果控制器产生的结果希望让人看到,那么它产生的模型数据需要渲染到视图中,从而可以展示到浏览器中,使用@Controller。

如果控制器产生的结果不需要让人看到,那么它产生的数据经过消息转换器直接返回到浏览器,使用@RestController。

参考链接:https://blog.csdn.net/u014116780/article/details/85225941

@RequestMapping

@GetMapping

@PostMapping

@PutMapping

@DeleteMapping

@RequestBody

@MapperScan

@ComponentScan

@Service

posted @ 2019-07-23 09:14  LearnSB  阅读(233)  评论(0编辑  收藏  举报