整理常用注解,及说明
1.package org.springframework.boot.autoconfigure
| 注解 | 说明 |
|---|---|
| @SpringBootApplication | SpringBoot项目程序启动入口配置,是一个复合注解,包含@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan |
\
2.package org.springframework.cloud.client
| 注解 | 说明 |
|---|---|
| @SpringCloudApplication | SpringCloud项目程序启动入口配置,是一个复合注解,包含@SpringBootApplication、@EnableDiscoveryClient、@EnableCircuitBreaker |
| @ConditionalOnDiscoveryEnabled |
\
3.package org.mybatis.spring.annotation
| 注解 | 说明 |
|---|---|
| @MapperScan | 扫描指定包下mybatis的接口文件 |
| @MapperScannerRegistrar | |
| @MapperScans |
\
4.package org.springframework.context.annotation
| 注解 | 说明 |
|---|---|
| @Bean | |
| @ComponentScan | 扫描和自动装配指标有@Component的类,并注册成bean,当然包括@Component下的子注解@Service,@Repository,@Controller。注解标记的类并纳入到spring容器中进管理 |
| @ComponentScans | 同时指定多个ComponentScan |
| @Conditional | |
| @Configuration | 用于定义配置类,可替换xml配置文件,内部包含有一个或多个被@Bean注解的方法,初始化Spring容器。 |
| @DependsOn | |
| @Description | |
| @EnableAspectJAutoProxy | |
| @EnableLoadTimeWeaving | |
| @EnableMBeanExport | |
| @Import | |
| @ImportResource | |
| @Lazy | 懒加载,当服务启动时,不进行初始化,调用时进行初始化, 可以减少容器启动的加载时间; 当出现循环依赖时,也可以添加@Lazy |
| @Primary | |
| @Profile | |
| @PropertySource | |
| @Role | |
| @Scope |
\
5.package org.springframework.web.bind.annotation
| 注解 | 说明 |
|---|---|
| @ControllerAdvice | 异常集中处理,更好的使业务逻辑与异常处理剥离开 |
| @CookieValue | |
| @CrossOrigin | |
| @DeleteMapping | |
| @ExceptionHandler | 统一处理某一类异常,从而能够减少代码重复率和复杂度 |
| @GetMapping | http get请求, 指定请求方式,路径等,默认封装了@RequestMapping(method = RequestMethod.GET) |
| @InitBinder | |
| @Mapping | |
| @MatrixVariable | |
| @ModelAttribute | |
| @package-info | |
| @PatchMapping | |
| @PathVariable | |
| @PostMapping | http post请求, 指定请求方式,路径等,默认封装了@RequestMapping(method = RequestMethod.POST) |
| @PutMapping | |
| @RequestAttribute | |
| @RequestBody | 用来接收POST请求的数据, @RequestBody与@RequestParam可以同时使用,最多一个RequestBody,可以有多个RequestParam |
| @RequestHeader | |
| @RequestMapping | |
| @RequestParam | 用来获取url中key=value的数据 |
| @RequestPart | |
| @ResponseBody | |
| @ResponseStatus | 映射为HTTP状态码 |
| @RestController | 应用于控制器, 包含@Controller @ResponseBody |
| @RestControllerAdvice | |
| @SessionAttribute | |
| @SessionAttributes | |
| @ValueConstants |
\
6.package springfox.documentation.swagger2.annotations
| 注解 | 说明 |
|---|---|
| @EnableSwagger2 | 开启Swagger2 |
\
7.package io.swagger.annotations
| 注解 | 说明 |
|---|---|
| @Api | |
| @ApiImplicitParam | |
| @ApiImplicitParams | |
| @ApiKeyAuthDefinition | |
| @ApiModel | |
| @ApiModelProperty | |
| @ApiOperation | |
| @ApiParam | |
| @ApiResponse | |
| @ApiResponses | |
| @Authorization | |
| @AuthorizationScope | |
| @BasicAuthDefinition | |
| @Contact | |
| @Example | |
| @ExampleProperty | |
| @Extension | |
| @ExtensionProperty | |
| @ExternalDocs | |
| @Info | |
| @License | |
| @OAuth2Definition | |
| @ResponseHeader | |
| @Scope | |
| @SecurityDefinition | |
| @SwaggerDefinition | |
| @Tag |
\
8.package org.springframework.beans.factory.annotation
| 注解 | 说明 |
|---|---|
| @Autowired | 对类成员变量进行标注,完成自动装配 |
| @Configurable | |
| @Lookup | |
| @Qualifier | |
| @Value | 从配置文件读取值 |
\
9.package lombok
| 注解 | 说明 |
|---|---|
| @AllArgsConstructor | |
| @Builder | |
| @Cleanup | |
| @CustomLog | |
| @Data | 主要省去大量Getter 和 Setter繁琐的写法 |
| @EqualsAndHashCode | |
| @Generated | |
| @Getter | |
| @NoArgsConstructor | |
| @NonNull | 不为空 |
| @RequiredArgsConstructor | |
| @Setter | |
| @Singular | |
| @SneakyThrows | |
| @Synchronized | |
| @ToString | |
| @val | |
| @Value | |
| @var | |
| @With |