我在Spring MVC项目(Spring Boot 1.4.2)的表单对象中使用了javax.validation.constraints.AssertTrue
注解。Spring验证@AssertTrue自定义错误代码/消息
我的班级与此类似:
public class CommandForm {
@NotEmpty
@Email
private String email;
// ...
@AssertTrue(message="{error.my.custom.message}")
public boolean isValid(){
// validate fields
}
}
方法isValid
正确调用和验证过程中正常工作,但我的自定义错误代码没有被正确解析。
我在我的message.properties
文件中有error.my.custom.message
字段,但是当验证失败时,我将"{error.my.custom.message}"
字符串作为错误消息而不是解析的消息。
我的代码有什么问题?这是设置自定义错误代码的正确语法吗?