如何使用 Lombok 访问 getter 和 setter 方法? [英] How to access getter and setter methods using Lombok?

查看:40
本文介绍了如何使用 Lombok 访问 getter 和 setter 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中添加了 Lombok maven 存储库并成功使用了 Lombok 注释.我试图从另一个类访问 setter 和 getter 方法,但无法访问这些方法.我正在使用 spring Boot 版本 2.1.1 和 STS.这是我的简单代码片段.

@Entity@Table(name = "角色")//@数据@ToString公共类角色{@Id @GeneratedValue(strategy=GenerationType.AUTO)@Column(name="role_id")私有整数 ID;@Column(名称=角色")@Getter @Setter(AccessLevel.PUBLIC)私有字符串角色;}

解决方案

您应该将它安装在您的 STS 中.按照说明操作:

双击 lombok.jar(可从

您可以在 eclipse 的 about 对话框中检查您的 eclipse 安装是否启用了 lombok.龙目岛版本会在版权文末列出:

来源:https://projectlombok.org/setup/eclipse

希望有帮助.

I've added Lombok maven repository in my project and successfully use the Lombok annotations. And I tried to access the setter and getter methods from another class but couldn't access those methods. I'm using spring Boot version 2.1.1 and STS. Here is my simple code snippet.

@Entity
@Table(name = "role")
//@Data
@ToString
public class Role {

    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="role_id")
    private int id;

    @Column(name="role")
    @Getter @Setter(AccessLevel.PUBLIC)
    private String role;        
}

解决方案

You should install it in your STS. Follow the instructions:

Double-click lombok.jar (downloadable from here, or from your maven repository; it's the same jar). This starts the eclipse installer which will find eclipse (and eclipse variants as listed above), and offers to install lombok into these eclipse installations. The same tool can also uninstall lombok:

You can check if your eclipse installation is lombok-enabled in eclipse's about dialog. The lombok version will be listed at the end of the copyright text:

Source: https://projectlombok.org/setup/eclipse

Hope it helps.

这篇关于如何使用 Lombok 访问 getter 和 setter 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆