我有MemberCreateDto
类,其中使用了AddressCreateDto
类:
public class MemberCreateDto {
private @NotEmpty @Size(min = 1, max = 80, message = "Please enter the name") String name;
private Optional<String> name;
@Valid
private Optional<AddressCreateDto> address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Optional<AddressCreateDto> getAddress() {
return address;
}
public void setAddress(Optional<AddressCreateDto> address) {
this.address = address;
}
}
public class AddressCreateDto {
@Size(max=12, message="Please be advised the status is restricted to 12 character length.")
private String streetNumber;
@Size(max=40, message="Please be advised the status is restricted to 40 character length.")
private String addressLine1;
public String getStreetNumber() {
return streetNumber;
}
public void setStreetNumber(String streetNumber) {
this.streetNumber = streetNumber;
}
public String getAddressLine1() {
return addressLine1;
}
public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}
}
如果我没有在private Optional<AddressCreateDto> address;
上方添加@Valid注释,则不会验证AddressCreateDto中的字段。
如果添加@Valid批注,则AddressCreateDto中的字段将得到验证,但会在错误消息中自动添加“地址”前缀。
如何删除前缀。