1
我正在使用带批注的Spring验证机制。验证必须在messages_en.properties
中配置。为此,请在此文件中输入password.min=4
。Spring MVC中的可配置验证
如何根据messageSource
bean中的设置配置@Size验证器?
public class SubmitModel {
@Size(min = "#{new Integer(messageSource[login.ok])}") //does not work. @Size expects integer value
private String password;
}
bean的配置:
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>lang\messages</value>
</property>
</bean>
我已经尝试配置静态常量,但在这里再次常量表达式的预期。 FYI,则需要该机制来验证在控制器中的进入的请求:
@RequestMapping (value = "/device/{devicename}", method = RequestMethod.GET, produces="text/xml")
@ResponseBody
public String handleRequest(@PathVariable("devicename") String devicename, @Valid @ModelAttribute SubmitModel model, BindingResult errors) throws UCLoginException { ... }
典型例子,其中该密码必须长于login.ok
值:http://my.domain.com:8080/submit/device/SPAxxxxx?name=adam&password=454321
感谢您的建议。它让我省了很多时间。 – luksmir