偷懒神器Lombok
1. 什么是Lombok?
- java library
- plugins
- build tools
2.使用步骤:
- 在IDEA中安装Lombok插件
- 在项目中导入lombok的jar包
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
- 在实体类上加注解即可!
@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
说明:
@Data: 无参构造、get、set、toString、hashCode、equals
@AllArgsConstructor,
@NoArgsConstructor
3. 结论
从此省去get set 构造器。