有没有办法在 Dropwizard 的验证错误消息中添加变量?效果中的一些东西
@ValidationMethod(message=String.format("Url cannot be null, field value = %s", fieldValue))
public boolean isNotValid() {
String fieldValue = this.getFieldValue();
return this.url == null;
}
我只想将变量添加到错误消息中。
最佳答案
我找到了答案。 Hibernate 5.1 有错误消息插值,可以解决这个问题。
@Size(min = 0, max = 0, message="${validatedValue} is present"))
public String getErrorMessage() {
List<String> illegalValues = ImmutableList.of("illegal value");
return illegalValues;
}
虽然有点麻烦,但它解决了问题。看看http://docs.jboss.org/hibernate/validator/5.1/reference/en-US/html/chapter-message-interpolation.html
关于java - Dropwizard 验证错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20875139/