为什么 quarku panache 示例中的 class 属性是 PUBLIC 而不是 PRIVATE

Why the class attributes in the quarku panache example are PUBLIC instead of PRIVATE

参考下面的入门link https://quarkus.io/guides/hibernate-orm-panache

该示例使用具有 public 属性的实体 class。

class Person{
 public String name;
}

并用作

person.name = "Synd";

所以它只是一个懒惰的例子(!! 在官方文档中?)还是有其他含义。

根据文档,这可能与一个差异有关(extending PanacheEntityBase)

If you don’t want to bother defining getters/setters for your entities, you can make them extend PanacheEntityBase and Quarkus will generate them for you. You can even extend PanacheEntity and take advantage of the default ID it provides.

因此他们正在制作它们 Public 以便 Quarkus 自动为您生成 getters/setters。

@Entity
public class Person extends PanacheEntity {
    public String name;
    public LocalDate birth;
    public Status status;

    public static Person findByName(String name){
        return find("name", name).firstResult();
    }

    public static List<Person> findAlive(){
        return list("status", Status.Alive);
    }

    public static void deleteStefs(){
        delete("name", "Stef");
    }
}

@Entity
public class Person {
    @Id @GeneratedValue private Long id;
    private String name;
    private LocalDate birth;
    private Status status;

    public Long getId(){
        return id;
    }
    public void setId(Long id){
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public LocalDate getBirth() {
        return birth;
    }
    public void setBirth(LocalDate birth) {
        this.birth = birth;
    }
    public Status getStatus() {
        return status;
    }
    public void setStatus(Status status) {
        this.status = status;
    }
}