SpringBoot集成lombook让代码更简洁

1)添加lombok依赖

<dependency>
           <groupId>org.projectlombok</groupId>
           <artifactId>lombok</artifactId>
         </dependency>

 

2)

@Slf4j//等同于
@Getter
@Setter
public class User {
    
   private String name;
   private Integer age;
    
    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return "username: "+name+"age:"+age;
    }
   //lombok底层使用字节码技术,ASM  帮你在内存中去修改字节码文件,生成getset方法
   //需要生成GetSet方法
    public static void main(String[] args) {
        User user =new User();
        user.setName("谭磊");
        user.setAge(20);
        log.info("AAA");
        System.out.println(user.toString());
        
    }
}

 

posted @ 2019-01-22 22:37  言西早石头侠  阅读(1702)  评论(0编辑  收藏  举报