1、File-Settings-Plugins-Brows Repositories-输入lombok-install
2、重启idea
3、添加maven依赖
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
4、用法
看下官方Features
@Getter and @Setter
@FieldNameConstants
@ToString
@EqualsAndHashCode
@AllArgsConstructor, @RequiredArgsConstructor and @NoArgsConstructor
@Log, @Log4j, @Log4j2, @Slf4j, @XSlf4j, @CommonsLog, @JBossLog, @Flogger
@Data
@Builder
@Singular
@Delegate
@Value
@Accessors
@Wither
@SneakyThrows
from Intellij 14.1 @val
from Intellij 15.0.2 @var
from Intellij 14.1 @var
from Intellij 2016.2 @UtilityClass
Lombok config system
Code inspections
Refactoring actions (lombok and delombok)
我们最关注的的几个注解:
@Getter @Setter @ToString @AllArgsConstructor,这4个注解直接用@Data即可
@Slf4j,省去之前用的Logger.getLogger(LogExample.class.getName());
@Builder 返回每个属性值的Builder,不用自己再去实现
使用此插件后,一个普通的Bean至少减少一半的代码量,出错几率也大大降低,pick用起来