如何将元素名称添加到自定义javax验证消息中

时间:2014-07-25 07:08:09

标签: java spring validation

在我的表单中,我使用javax.validation

@Size(max = 10, min = 9)
String myField;

并且在ValidationMessages.properties中我定义了我的自定义消息:

javax.validation.constraints.Size.message = Size should be between {min} and {max}

但现在我想要包含类似Size of {field} should be between {min} and {max}

的字段名称

是否可以使用此属性文件添加字段名称?

1 个答案:

答案 0 :(得分:0)

只做

myfield.size.message = myField should be between {min} and {max}

并改变:

@Size(max = 10, min = 9)
String myField;

@Size(max = 10, min = 9, message = "{myfield.size.message}")
String myField;

message.size=should be between {min} and {max}

@Size(max = 10, min = 9, message = "myfield {message.size}")
String myField;