Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 消息插值不工作_Java_Spring_Spring Mvc - Fatal编程技术网

Java 消息插值不工作

Java 消息插值不工作,java,spring,spring-mvc,Java,Spring,Spring Mvc,我正在尝试设置一个API,在将请求映射到数据传输对象时进行验证。我在插入数据库驱动的消息源时遇到问题。my DB中的记录具有占位符: id,oplock,code,msg,locale 9,0,minmax_password,"Password length should be a minimum of {1} and maximum of {2}.","en" 我有此数据传输对象,该对象应映射到具有此属性的请求: @NotBlank(message = "{notnull_passwor

我正在尝试设置一个API,在将请求映射到数据传输对象时进行验证。我在插入数据库驱动的消息源时遇到问题。my DB中的记录具有占位符:

 id,oplock,code,msg,locale
 9,0,minmax_password,"Password length should be a minimum of {1} and maximum of {2}.","en"
我有此数据传输对象,该对象应映射到具有此属性的请求:

@NotBlank(message = "{notnull_password}")
@Size(min = 6, max = 20,message = "{minmax_password}")
private String password;
这是我的XML设置:

 <beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <beans:property name="validationMessageSource" ref="messageSourceServiceImp"/>
</beans:bean>

 <mvc:annotation-driven validator="validator">
 </mvc:annotation-driven>
如果我遗漏了什么,请告诉我


谢谢

Hibernte验证器似乎没有使用数值索引{1}、{2}等等。因此,我必须使用{min}、{max}。同样对于数据库驱动的MessageSource,它通常返回MessageFormat对象。此对象需要数字索引,而不是文本。使用{min}会引发NumberFormatException,因为它无法解析min。因此,您需要做的是将{min}放在单引号中;这将告诉MessageFormat忽略该部分。例如:

 9,0,minmax_password,"Password length should be a minimum of '{min}' and maximum of '{max}'.","en"
希望这有帮助

 9,0,minmax_password,"Password length should be a minimum of '{min}' and maximum of '{max}'.","en"