如何通过lombook anotations从jpa Entity anotate获取字段值?

时间:2017-07-13 22:32:07

标签: java spring hibernate jpa lombok

我的实体类注释了 lombook annonation(https://projectlombok.org/features/all):

@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]);
        });

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

2 个答案:

答案 0 :(得分:0)

启用“注释处理”。

Error: The method eth_getCompilers does not exist/is not available
at web3.js:3104:20
at web3.js:6191:15
at web3.js:5004:36
at <anonymous>:1:1

答案 1 :(得分:0)

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