Apache Isis 如何显示值对象



最近,我用Apache Isis构建了我的DDD项目。

现在,我有一个实体对象客户,我认为客户可能有很多值对象,例如。客户联系信息。

public class Customer extends AbstractEntityObject{
@Column(allowsNull = "false")
@Getter
private String name;
@Column(allowsNull = "false")
@Getter
private String idcard;
@Column(allowsNull = "false")
@Getter
private CustomerIdType idtype;
public Customer(String name,String idcard,CustomerIdType idtype) {
this.name = name;
this.idcard = idcard;
this.idtype = idtype;
}
@Persistent(mappedBy="customer",dependentElement="false")
@Column(allowsNull="true")
@Setter @Getter
private CustomerContactInfomation contact;
}

public class CustomerContactInfomation {
@PrimaryKey
@Column(name = "customerId")
@Getter
private Customer customer;
@Column(allowsNull = "true")
@Setter @Getter
private String phone;
}
客户

联系信息只是一个价值对象,它不能有任何操作,应该由客户维护。

客户-客户联系信息肯定是1-1。

现在,我应该如何在客户中显示客户联系信息并能够编辑客户联系信息?

我不确定我会将客户联系信息描述为一个值对象...它有一个主键,因此使其成为持久实体,并且其 phone 属性也是可变的。

但要把它放在一边...我认为应该有可能得到你所追求的效果。 您可能已经看到,框架会将 Customer#contact 属性呈现为 CustomerContactInformation 对象的超链接。 为了允许客户维护其电话属性,我建议对客户执行简单的操作,例如:

@MemberOrder(named="contact", sequence="1")
public Customer updateContact(String newPhone) {
this.contact.setPhone(newPhone);
return this;
}

@MemberOrder#name 批注将导致此按钮的操作在 contact 属性下呈现。

呵呵 担

最新更新