fluent-validator
fluent-validator copied to clipboard
为什么ValidationError的ErrorCode必须是Integer?
因为我们项目中使用的ErrorCode是用String数据类型,所以String数据类型感觉会更通用一些吧。
嗯呢,ErrorCode用string或者int这个没有准则吧,只是这个类库选择了int,code一般都会有错误码,数字达意了。
Just extends ValidationError like I did. Example:
public class FluentValidationError extends ValidationError {
private String errorKey;
public String getErrorKey() {
return errorKey;
}
public FluentValidationError setErrorKey(String errorKey) {
this.errorKey = errorKey;
return this;
}
}
@tiagocpeixoto great catch!
也遇到了相同的问题,现在项目定义的 ErrorCode 是 string类型
项目初始考虑欠佳,可以通过上面 tiagocpeixoto 的扩展方式workaround支持下。