如何使用Lombok访问getter和setter方法

如何使用Lombok访问getter和setter方法

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

问题描述

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

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

您应将其安装在STS中.请按照说明进行操作:

双击lombok.jar(可从

您可以在eclipse的关于"对话框中检查您的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方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:34