一、相关说明
Lombok是一个可以通过注解形式在编译源码的时候生成对应getter、setter、equals、hashcode、toString等方法的工具类库,帮助我们消除重复工作和简化相关代码
官方地址:https://projectlombok.org/;Github地址:https://github.com/rzwitserloot/lombok
二、插件安装
下载lombok.jar包并执行,点击安装界面中 Specify location按钮,选中eclipse.exe, 点击Install/Update,即可安装。安装原理即在eclipse.ini中设置javaagent属性
三、添加依赖
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.2</version>
</dependency>
四、常用注解
@Getter: 注解在 类 上,会对所有的非静态(non-static)属性生成Getter方法,放在属性上,会对该属性生成Getter方法。并可以指定Getter方法的访问级别
@Setter: 放在 类 上,会对所有的非静态(non-static)属性生成Setter方法,放在属性上,会对该属性生成Setter方法。并可以指定Setter方法的访问