- <!--数据验证-->
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <version>4.0.1.GA</version>
- </dependency>
- <!--jboss logging-->
- <dependency>
- <groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging</artifactId>
- <version>3.3.0.Final</version>>
- </dependency>
- <!--validation api-->
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- <version>1.0.0.GA</version>
- </dependency>
- <!--slf4j api-->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.21</version>>
- </dependency>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/mvc
- http://www.springframework.org/schema/mvc/spring-mvc.xsd
- ">
- <!--配置 包 扫描器-->
- <context:component-scan base-package="cn.hello.Valldator"/>
- <bean id="myValltor" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
- <property name="providerClass" value="org.hibernate.validator.HibernateValidator"></property>
- </bean>
- <mvc:annotation-driven validator="myValltor"></mvc:annotation-driven>
- </beans>
- <h1>数据校验</h1>
- <form action="/first" method="post">
- 成绩:<input name="score" /> <span>${scoremsg }</span><br/><br/>
- 姓名:<input name="name"/><span>${namemsg }</span><br/><br/>
- 电话:<input name="phone"/><span>${phonemsg }</span><br/><br/>
- <input type="submit" value="注册"/>
- </form>
- <body>
- 欢迎你
- </body>