Add 1 lombok
dependent
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
2 entity class presentation
@Slf4j
@Data
public class UserEntity {
private String userName;
private Integer age;
@Override
public String toString() {
return "UserEntity [userName=" + userName + ", age=" + age + "]";
}
public static void main(String[] args) {
UserEntity userEntity = new UserEntity();
userEntity.setUserName("zhangsan");
userEntity.setAge(20);
System.out.println(userEntity.toString());
log.info("####我是日志##########");
}
}
3 Other Features
@Data
Tag, generating getter / setter toString () method and the like
@NonNull
: So you do not worry about falling in love and NullPointerException
@CleanUp
: Automatic Resource Management: no need to add resources in a finally close in
@Setter/@Getter
: Automatically generating set and get methods
@ToString
: The method of automatically generating toString
@EqualsAndHashcode
: Generates a hashCode and equals from the object field
@NoArgsConstructor/@RequiredArgsConstructor/@AllArgsConstructor
Automatically generated constructor
@Data
: Generated automatically set / get method, toString method, equals method, the hashCode method, constructor with no arguments
@Value
: For the annotation final class
@Builder
: Generating complex builder class api
@SneakyThrows
: Exception Handling (with caution)
@Synchronized
: Safety synchronization method of transformation
@Getter(lazy=true)
@Log
: Logger supports a variety of objects, with the use of the corresponding annotation, such as: @ Log4