Command校验
@Builder
public class StudentCommand {
private long id;
private String name;
private String description;
}
通过new的方式实现
@Builder
public class StudentCommand {
private long id;
private String name;
private String description;
public static StudentCommand of (long id, String name, String description) {
if (description.length() > 100) {
throw new Exception();
}
return new StudentCommand(id, name, description)
}
}
@Builder
public class StudentCommand {
private long id;
private String name;
private String description;
public static StudentCommand of (long id, String name, String description) {
if (description.length() > 100) {
throw new Exception();
}
return StudentCommand.builder()
.id(id)
.name(name)
.description(description)
.build()
}
}
重写Build,加入校验
@Builder
public class StudentCommand {
private long id;
private String name;
private String description;
public static class StudentCommandBuilder {
public StudentCommand.StudentCommandBuilder description (String des) {
if (des.length() > 100) {
throw new Exception();
}
this.description = des;
return this;
}
}
}