代码已上传至Github,有兴趣的同学可以下载来看看:https://github.com/ylw-github/SpringBoot-Log4j-Demo
SpringBoot集成lombok可以让代码更简洁,下面来讲讲lombok的集成与使用。
1. 集成与使用步骤一:添加lombok依赖
org.projectlombok
lombok
步骤二:实体类
package com.ylw.springboot.lombok;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Data
public class UserEntity {
@Getter
@Setter
private String userName;
@Getter
@Setter
private Integer age;
@Override
public String toString() {
return "UserEntity [userName=" + userName + ", age=" + age + "]";
}
}
步骤三:单元测试
import com.ylw.springboot.lombok.UserEntity;
import org.junit.Test;
public class LomBokTest {
@Test
public void test(){
UserEntity userEntity = new UserEntity();
userEntity.setUserName("zhangsan");
userEntity.setAge(20);
System.out.println(userEntity.toString());
}
}
运行结果: