我想创建一个具有以下规格的 Spring Boot 托控制器:
电力及气体供应公司的客户可选择透过电邮或平邮收取每月帐单,或两者皆收,或两者皆收。
我的目标是创建java hib实体来管理这些客户和他们发送账单的选择。
公用事业客户由其电子邮件标识,并且可以具有更改客户选择状态的多项选择更改事件。
客户做出的每个选择都会生成一个选择更改事件。
选择更改事件与客户相关。客户可以具有多个选择事件。
下面是我的java实体。
@Entity
@Table(name = "customers")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Email(message="this field must respect the email format !")
private String email;
@ManyToOne
private Choices choices;
}
@Entity
@Table(name = "choices")
public class Choices {
@Id
private String id;
@Column(name = "email")
private boolean isThisChoice;
@OneToOne
private Customer customer;
}
The resulting customer with id 24587 (GET request):
{
"id": "24587",
"email": "tartampion",
"choices": [
{
"id": "regular mail",
"isThisChoice": false
},
{
"id": "email",
"isThisChoice": true
}
]
}
我必须有一个客户选择的事件管理实体吗
2条答案
按热度按时间taor4pac1#
这里你必须使用多对多Map。因为一个客户可以有很多选择,而一个选择可以被很多客户选择。
polkgigr2#
您是指更像以下的模型吗:
这将为您提供一个选择Map,从而使JSON更像:
如果你在未来得到其他的选择和组合,它应该会扩展得多。
同样,您可以使用相同的表格结构,将“Choices”作为实体: