zoukankan      html  css  js  c++  java
  • @validated各种坑

    1.@validate不起作用

    经过各种测试,在@validate后加了个modelattribute("form")就不验证了,坑。。

    2.错误信息的properties配置文件无法读出来

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <!-- 配置校验器 -->
        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
            <!-- 校验器,使用hibernate校验器 -->
            <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
            <!-- 指定校验使用的资源文件,在文件中配置校验错误信息,如果不指定则默认使用classpath下面的ValidationMessages.properties文件 -->
            <property name="validationMessageSource" ref="messageSource"/>
        </bean>
        <!-- 校验错误信息配置文件 -->
        <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <!-- 资源文件名 -->
            <property name="basenames">
                <list>
                    <value>validationmessages</value>
                </list>
            </property>
            <!-- 资源文件编码格式 -->
            <property name="fileEncodings" value="utf-8"/>
            <!-- 对资源文件内容缓存时间,单位秒 -->
            <property name="cacheSeconds" value="120"/>
        </bean>
    </beans>

    参考网上配置,搞不定,网上是

    <list>
                <value>classpath:CustomValidationMessage</value>
            </list>
    在idea下用class:直接飘红,都试了试,不管有没有class都读不出来。
    然后改成ValidationMessages这个名字,直接就好用了。
    也就是
    <list>
                <value>ValidationMessages</value>
            </list>
    ValidationMessages
  • 相关阅读:
    Delphi程序结构
    SQL存储过程解密 Encrypted object is not transferable, and script can not be generated

    在河南呢
    还在河南,写随笔吧
    HAVING
    mIRC
    关于CAP理论
    开篇
    移动信息系统
  • 原文地址:https://www.cnblogs.com/ptqueen/p/8574083.html
Copyright © 2011-2022 走看看