lombok在spring 中的使用

Lombok是一款Java库,能够自动集成到编辑器和构建工具中,通过注解方式自动生成getter、setter、构造器等,简化代码编写。支持日志自动化,与Spring Boot无缝集成。使用@Data、@Getter/@Setter等注解快速生成类方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 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.

spring boot 中的使用

  • 引入依赖
<groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.10</version>
            <scope>compile</scope>
  • 直接用注解的方式使用
@Data 可以自动为实体类生成getter setter toString equal constructor 等方法
@Getter @Setter 可以为属性生成getter setter 方法
@ToString(callSuper=true,exclude="someExecludeField")
@EqualAndHashCode(callSuper=true,exclude={"",""})

更多其实只是使用期日志记录:
@Slf4j 对于一个类使用即可用log变量来记录-log.info("")

注意 还可以使用@Log @Log4j等等 不同的日志产品有不同的实现

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值