在springmvc中使用hibernate-validate

论坛 期权论坛 脚本     
匿名技术用户   2021-1-2 17:33   50   0

在springmvc中使用hibernate-validate

http://www.cnblogs.com/leechenxiang/p/5490930.html

在springmvc.xml中加入

<!-- 国际化配置 --> 
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:resource/ValidationMessages</value>
</list>
</property>
<property name="useCodeAsDefaultMessage" value="true" />
</bean>
<!-- 注册验证器 -->
<mvc:annotation-driven validator="validator" />

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="providerClass" value="org.hibernate.validator.HibernateValidator" />
<!-- 这里配置将使用上面国际化配置的messageSource -->
<property name="validationMessageSource" ref="messageSource" />
</bean>

依赖包:

validation-api.jar
hibernate-validator.jar


    <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.2.Final</version>
    </dependency>

posted @ 2017-08-18 11:19 wdmiye 阅读(...) 评论(...) 编辑 收藏
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP