一、前言
在我们使用java语言定义实体对象的时候,以前经常需要写set和get方法,会觉得很繁琐。偶然接触到一款神器叫Lombok的,可以帮我们很好的解决这种琐事。
二、步骤
1、在idea上安装Lombok插件
File-Settings-Plugins,搜索Lombok
下载后,需要重启idea生效
2、在pom文件添加相关依赖
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.20</version> <scope>provided</scope> </dependency>
三、测试类
import lombok.Data; @Data public class Text { private String content; }
idea编译之后的:
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package restassureddemo.weixin; public class Text { private String content; public Text() { } public String getContent() { return this.content; } public void setContent(String content) { this.content = content; } public boolean equals(Object o) { if (o == this) { return true; } else if (!(o instanceof Text)) { return false; } else { Text other = (Text)o; if (!other.canEqual(this)) { return false; } else { Object this$content = this.getContent(); Object other$content = other.getContent(); if (this$content == null) { if (other$content != null) { return false; } } else if (!this$content.equals(other$content)) { return false; } return true; } } } protected boolean canEqual(Object other) { return other instanceof Text; } public int hashCode() { int PRIME = true; int result = 1; Object $content = this.getContent(); int result = result * 59 + ($content == null ? 43 : $content.hashCode()); return result; } public String toString() { return "Text(content=" + this.getContent() + ")"; } }
说明生效