Lombok 简化实体类开发
程序员文章站
2022-06-15 23:37:57
...
Lombok
- java library
java库
- plugs
插件
- build tools
构建工具
- with one annotation your class
在类上注解
使用步骤:
1.在idea中安装Lombok插件
2.在项目中导入Lombok的jar包
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
3.在实体类上使用注解
@Getter and @Setter
@FieldNameConstants
@ToString
@EqualsAndHashCode
@AllArgsConstructor, @RequiredArgsConstructor and @NoArgsConstructor
@Log, @Log4j, @Log4j2, @Slf4j, @XSlf4j, @CommonsLog, @JBossLog, @Flogger, @CustomLog
@Data
@Builder
@SuperBuilder
@Singular
@Delegate
@Value
@Accessors
@Wither
@With
@SneakyThrows
@val
@var
experimental @var
@UtilityClass
说明:
@Data:无参构造、get、set、toString、hashcode、equals
@AllArgsConstructor
@NoArgsConstructor
4.测试
Lombok有利有弊谨慎使用!了解即可