如何使用 lombok 注释从 jpa 实体注释中获取字段值?

How to get field value from jpa Entity annotate with lombook annotations?

我用 lombook 注释 (https://projectlombok.org/features/all):

注释了实体 class
@Getter
@Setter
@EqualsAndHashCode
@ToString
@RequiredArgsConstructor

@NoArgsConstructor
@AllArgsConstructor
@Builder

@Entity
@Table(name = "members")
public class Member implements Serializable {
    private final static long serialVersionUID= 1l;
    @id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="id", unique = true)
    private Long id;
    @Column(name="name")
    @NonNull
    private String name;
    @Column(name="photo")
    @NonNull
    private String photo;
    @Column(name="descriotion")
    private String descriotion;
    @Column(name="winner_in_period")
    private String winnerInPeriod;
    @Column(name="created_date")
    private Date createdDate;
    @Column(name="deleted")
    private Boolean deleted;
}

而且我有使用此实体从数据库中为我提供数据的服务。 最后我尝试从 Member 对象中获取一些数据

    List<Member> lastMembers = memberService.getMembers(0, lastMembersCount);

    if(lastMembers != null)
        lastMembers.forEach(member -> {
            System.out.println(member.[IN THIS PLACE I DONT HAWE ANY GETTERS for table field]);
        });

但我在成员对象中没有任何 getter。当我写 member.getName() 时出现错误(IDEA 建议我创建 getter 'getName()')。 如何将 lombook 与 jpa 实体一起使用? 如何访问标有 lombok 注释的字段,如 @Getter@Setter ?

启用"annotation processing".

Build, Execution, Deployment -> Compiler -> Annotation Processor: Enable annotation processing

如果你想使用'lombok'你应该安装IDEA插件并重启IDEA。在这个简单的步骤之后,一切都会很好地工作。 龙目岛很棒