为什么要在java db实体中使用公共接口?

时间:2018-11-19 16:41:03

标签: java interface pojo

我在查看其他项目时发现了此代码段,我想知道在Java pojo中使用公共接口的好处。如以下示例所示,为什么要使用它。以下用途是否被视为最佳做法?使用界面喜欢这个吗?

@Data
@NoArgsConstructor
@Entity
@Table(name = "customer_mapping", schema = "billing")
public class CustomerMapping {
    public interface createCustomerMapping {
    }

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonProperty("customerMappingId")
private Integer id;

@Column(length=10)
@NotNull(groups = { createCustomerMapping.class })
@NotEmpty(groups = { createCustomerMapping.class })
@Size(groups = { createCustomerMapping.class }, min = 4, max = 4)
private String issuerCode;

@Column(length=10)
@NotNull(groups = { createCustomerMapping.class })
@NotEmpty(groups = { createCustomerMapping.class })
private String offerCode;

@NotNull
private Long customerId;

@CreationTimestamp
private LocalDateTime createdTs;

private String createdBy;

@UpdateTimestamp
private LocalDateTime updatedTs;

private String updatedBy;

public CustomerMapping(String offerCode) {
    this.offerCode = offerCode;
}

public CustomerMapping(String issuerCode, String offerCode) {
    this.issuerCode = issuerCode;
    this.offerCode = offerCode;
}

public CustomerMapping(String issuerCode, String offerCode, Long customerId) {
    this.issuerCode = issuerCode;
    this.offerCode = offerCode;
    this.customerId = customerId;
}
}

据我所知,接口是用来定义合同的,所以我熟悉通过代码库或两个团队需要合作使用该接口的实现。但是在上面的示例中,我不清楚。

0 个答案:

没有答案