我只想确认你们是否认为这是一个好习惯:
使用 javax.validation.constraints 注释用一些验证在 java 中编写实体类
编写单元测试以断言验证
编写单元测试来断言 getter 和 setter,因为这是一种断言该类包含我们需要的所有字段的方法
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(exclude = "client")
@Data
@Entity
@Table(name = "addresses")
public class Address extends BaseEntity {
private static final long serialVersionUID = -5966581124342250987L;
@NotNull
@Size(min = 2, max = 40)
@Column(name = "line1", nullable = false, length = 40)
private String line1;
@Size(min = 2, max = 40)
@Column(name = "line2", length = 40)
private String line2;
@NotNull
@Size(min = 2, max = 40)
@Column(name = "city", length = 40)
private String city;
@NotNull
@Size(min = 2, max = 2)
@Column(name = "country_code", length = 2)
private String countryCode; //code ISO 3166 two-letter country codes
@NotNull
@EqualsAndHashCode.Exclude
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id")
private Client client;
}
慕码人2483693
犯罪嫌疑人X
长风秋雁
相关分类