您的位置:首页 > 编程语言 > Java开发

SpringBoot -- 常见注解

2018-11-12 23:45 239 查看
版权声明:欢迎转载,转载请注明出处 https://blog.csdn.net/ausu1212/article/details/84001010
@SpringBootApplication

在启动类上可以看到这个注解,标识该类为启动类。改注解其实是一个组合注解,由

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan
组成。

@SpringBootConfiguration
继承自
@Configuration
,两者功能已知,标识该类为配置类,讲当前类中
@Bean
注解的方法的实例纳入spring容器中,并且实例名就是方法名,从而实现用Java代码替代传统的xml配置。

@EnableAutoConfiguration
会基于添加的
spring-boot-starter-*
依赖,采用“约定由于配置”的方式去配置项目。

@ComponentScan
组件扫描,扫描到有
@Controller
@Service
等注解的类,将其注册为Bean,纳入spring容器管理中。

@RestController

该注解也是一个组合注解,由

@Controller
@ResponseBody
组合而成。

@RequestMapping
相关

Spring4开始新增了几个注解如:

@GetMapping
@PostMapping
@PutMapping
@DeleteMapping
等。

@GetMapping
等价于
@RequestMapping(method = RequestMethod.GET)
标识该方法为Get方法,其他分别为Post、Put、Delete方法,用于Restful风格中,分别对应着查、增、改、删。

待添加,欢迎留言

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: