1

最近,我使用 Apache Isis 构建了我的 DDD 项目。</p>

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

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;

}

CustomerContactInfomation 只是一个值对象,它不能有任何动作,应该由客户维护。

Customer-CustomerContactInfomation 绝对是 1-1。

现在,我应该如何在 Customer 中显示 CustomerContactInfomation 并能够编辑 CustomerContactInfomation?

4

1 回答 1

0

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

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

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

@MemberOrder#name 注释将导致此按钮的操作在联系人属性下呈现。

HTH丹

于 2017-08-13T17:07:09.803 回答