IDEA 安裝lombok及使用

一、File-Settings-Plugins-Brows Repositories-輸入lombok-installmaven

二、重啓ideaide

三、添加maven依賴ui

<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <version>1.16.10</version>
</dependency>idea

四、用法插件

看下官方Featuresget

@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)
it

 

咱們最關注的的幾個註解:io

@Getter  @Setter @ToString @AllArgsConstructor,這4個註解直接用@Data便可class

@Slf4j,省去以前用的Logger.getLogger(LogExample.class.getName());sso

@Builder 返回每一個屬性值的Builder,不用本身再去實現

 

使用此插件後,一個普通的Bean至少減小一半的代碼量,出錯概率也大大下降,pick用起來

相關文章
相關標籤/搜索