Lombok项目是一个java库,它可以自动插入到编辑器和构建工具中,增强java的性能。不需要再写getter、setter或equals方法,只要有一个
注解
,你的类就有一个功能齐全的构建器、自动记录变量等等。
使用步骤:
1.在idea中安装Lombok插件
2.在项目中导入Lombok的jar包
https://mvnrepository.com/artifact/org.projectlombok/lombok
<!– https://mvnrepository.com/artifact/org.projectlombok/lombok –>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</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(无参构造)
@EqualsAndHashCode
@ToString