Java 记录验证注释
Java records validation anotation
我有带有效注释的旧 POJO:
public class SomeData {
@NotNull(message = "Data not be null")
private String data;
public FormData(String data) {
this.data = data;
}
public String getData() {
return data;
}
public String setData(String data) {
this.data = data
}
}
但知道我有 records
public record SomeData(String data) {}
如何在记录中添加注释?
你可以这样做:
public record SomeData(@NotNull(message = "Data not be null") String data) {}
我有带有效注释的旧 POJO:
public class SomeData {
@NotNull(message = "Data not be null")
private String data;
public FormData(String data) {
this.data = data;
}
public String getData() {
return data;
}
public String setData(String data) {
this.data = data
}
}
但知道我有 records
public record SomeData(String data) {}
如何在记录中添加注释?
你可以这样做:
public record SomeData(@NotNull(message = "Data not be null") String data) {}