👉 官网:https://projectlombok.org/
- Gitee 镜像:https://gitee.com/mirrors/lombok
- Github:https://github.com/rzwitserloot/lombok
👉 最新版本:1.18.30(2023/09/20 发布,支持 JDK 21,jar 包 1.9MB)
Lombok 是一个 Java 实用工具,通过提供 Lombok 注解,来帮助开发人员消除冗长的代码,尤其是 POJO。
官方简介
官方介绍:Spice up your java: Automatic Resource Management, automatic generation of getters, setters, equals, hashCode and toString, and more!
中文翻译:给你的 java 加点料,比如自动化资源管理、自动生成常用方法(比如 setter/getter/equals/hashCode/toString 等)。
入门示例 - Hello World
下面,我们具体看个例子,就能体会到 **加点料 **是什么意思了。
🤷 典型场景:Java 中 POJO 中定义了很多属性,导致代码冗长。
示例代码如下:有好几个属性,代码不简洁,冗长,但又必须写。
package com.ganlan.cloud.common;
public class User {
private Long id;
private String name;
private String uid;
private String email;
private String deptName;
private Integer age;
private String comments;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUid