Lombok使用

Lombok


解释:

Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.
Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more.

重点:

  • java library Java库
  • plugs 插件
  • build tools 构建工具
  • with one annotation your class 在类上打上注解

1.使用步骤

  1. 在IDEA中安装Lombok插件
  • File–>Settings–>plugins–>搜索Lombok下载
  1. 在项目中导入lombok的jar包
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.26</version>
</dependency>

  1. 在实体类上加上注解即可
@Data//无参构造,get set toString hashCode,equals...
@AllArgsConstructor//有参构造,发现无参构造没了 显示的定义了有参构造之后 必须显示定义无参构造
@NoArgsConstructor//无参构造

/**
 * 实体类
 */
@Data//无参构造,get set toString hashCode,equals...
@AllArgsConstructor//有参构造,发现无参构造没了 显示的定义了有参构造之后 必须显示定义无参构造
@NoArgsConstructor//无参构造
public class User {
    private int id;
    private String name;
    private String password;
    //也还可以自己加

}

其他注解:

@Getter and @Setter
@FieldNameConstants
@ToString
@EqualsAndHashCode
@AllArgsConstructor, @RequiredArgsConstructor and @NoArgsConstructor
@Log, @Log4j, @Log4j2, @Slf4j, @XSlf4j, @CommonsLog, @JBossLog, @Flogger
@Data
@Builder
@Singular
@Delegate
@Value
@Accessors
@Wither
@SneakyThrows

比较常见的:

@Data:无参构造,get、set、tostring、hashcode,equals
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@ToString
@Getter
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~久违~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值