과거에는 개체 모델 코드, 우리는 그래서 다른 생성자와 왕창뿐만 아니라 설정 가져 오기를 / 작성해야 할 때. 롬복은 우리를 위해 아주 좋은 플러그인을 제공합니다.
대부분의 프로젝트에서는, 당신은 당신이를 참조하십시오, 더 많은 옵션을 볼 필요가있는 경우, 충분한 다음 중앙 주석을 사용할 필요가 : 포털
@Getter
@Setter
@ToString
@RequiredArgsConstructor
최종 필드 생성자를 생성
/**
* java class
*/
@RequiredArgsConstructor
class UserVO {
private final Integer id;
private final String name;
private int age;
}
/**
* 编译后生成的代码
*/
class UserVO {
private final Integer id;
private final String name;
private int age;
public UserVO(Integer id, String name) {
this.id = id;
this.name = name;
}
}
@Data
조합 코멘트
/**
* @see Getter
* @see Setter
* @see RequiredArgsConstructor
* @see ToString
* @see EqualsAndHashCode
* @see lombok.Value
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Data {
/**
* ...
*/
String staticConstructor() default "";
}
@Builder
원래 할당 모드를 변경
- 전에 사용
- 사용 후 (빌더 패턴을 널리 척하기 소스 코드에서 사용되었다)
@Slf4j
람에 해당 구비
public static final Logger LOGGER =
LoggerFactory.getLogger(UserCenterApplication.class);
/**
* This annotation is valid for classes and enumerations.<br>
* @see <a href="https://www.slf4j.org/api/org/slf4j/Logger.html">org.slf4j.Logger</a>
* @see <a href="https://www.slf4j.org/api/org/slf4j/LoggerFactory.html#getLogger(java.lang.Class)">org.slf4j.LoggerFactory#getLogger(java.lang.Class)</a>
* @see lombok.extern.apachecommons.CommonsLog @CommonsLog
* @see lombok.extern.java.Log @Log
* @see lombok.extern.log4j.Log4j @Log4j
* @see lombok.extern.log4j.Log4j2 @Log4j2
* @see lombok.extern.slf4j.XSlf4j @XSlf4j
* @see lombok.extern.jbosslog.JBossLog @JBossLog
* @see lombok.extern.flogger.Flogger @Flogger
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface Slf4j {
/** @return The category of the constructed Logger. By default, it will use the type where the annotation is placed. */
String topic() default "";
}