简介: lombok 通过简单注解方式简化java代码。(如消除实体对象的get/setter方法、日志对象声明等...)
安装步骤:
1、选择支持注解处理:Settings-->Build-->Annotation Processors-->勾选上Enable annotation processing
2、安装插件:Settings-->Plugins-->单击Browse repositories
查找lombok插件并进行安装:
3、新增lombok maven jar包依赖:
<!--日志封装类-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
4、新增lombok maven插件支持:
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
</plugin>
使用lombok案例
未使用lombok代码:
import java.io.Serializable;
import java.util.Date; public class UserBean implements Serializable {
private static final long serialVersionUID = -3083532522233597386L; private String userId; private String userName; private String password; private Date birthDay; private String mobile; private String email; private Date createdDate; public String getUserId() {
return userId;
} public void setUserId(String userId) {
this.userId = userId;
} public String getUserName() {
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public Date getBirthDay() {
return birthDay;
} public void setBirthDay(Date birthDay) {
this.birthDay = birthDay;
} public String getMobile() {
return mobile;
} public void setMobile(String mobile) {
this.mobile = mobile;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public Date getCreatedDate() {
return createdDate;
} public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
}
使用lombok后的代码:
import lombok.Data;
import java.io.Serializable;
import java.util.Date; @Data
public class UserBean implements Serializable {
private static final long serialVersionUID = -3083532522233597386L; private String userId; private String userName; private String password; private Date birthDay; private String mobile; private String email; private Date createdDate; }
日志使用
1、在类上增加注解@Slf4j
2、方法体中直接用使用log