springmvc數據顯示

  1. <!--數據驗證-->  
  2.    <dependency>  
  3.    <groupId>org.hibernate</groupId>  
  4.    <artifactId>hibernate-validator</artifactId>  
  5.    <version>4.0.1.GA</version>  
  6.    </dependency>  
  7.   
  8.    <!--jboss logging-->  
  9.    <dependency>  
  10.      <groupId>org.jboss.logging</groupId>  
  11.      <artifactId>jboss-logging</artifactId>  
  12.      <version>3.3.0.Final</version>>  
  13.    </dependency>  
  14.   
  15.   
  16.    <!--validation api-->  
  17.    <dependency>  
  18.      <groupId>javax.validation</groupId>  
  19.      <artifactId>validation-api</artifactId>  
  20.      <version>1.0.0.GA</version>  
  21.    </dependency>  
  22.   
  23.      <!--slf4j api-->  
  24.      <dependency>  
  25.          <groupId>org.slf4j</groupId>  
  26.          <artifactId>slf4j-api</artifactId>  
  27.        <version>1.7.21</version>>  
  28.      </dependency>  
  1. public class UserInfo {  
  2.     //必須是0到100之間  
  3.     @Min(value = 0,message = "成績最小值爲{value}")  
  4.     @Max(value = 100,message = "成績最大值爲{value}")  
  5.     private Integer score;  
  6.     //手機號碼不爲空  
  7.         @NotEmpty(message = "手機號碼不能爲空")  
  8.         @Pattern(regexp = "^1[3,4,5,6,7,8,9]\\d{9}$",message = "手機號碼不正確")  
  9.         private  String phone;  
  10.         //用戶名 不爲空  
  11.     @NotEmpty(message = "用戶名不能爲空")  
  12.     @Size(min = 6,message = "名稱至少6個字符")  
  13.     private  String name;  
  14.   
  15.     public Integer getScore() {  
  16.         return score;  
  17.     }  
  18.   
  19.     public void setScore(Integer score) {  
  20.         this.score = score;  
  21.     }  
  22.   
  23.     public String getPhone() {  
  24.         return phone;  
  25.     }  
  26.   
  27.     public void setPhone(String phone) {  
  28.         this.phone = phone;  
  29.     }  
  30.   
  31.     public String getName() {  
  32.         return name;  
  33.     }  
  34.   
  35.     public void setName(String name) {  
  36.         this.name = name;  
  37.     }  
  38. }  
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  xmlns="http://www.springframework.org/schema/beans"  
  3.         xmlns:aop="http://www.springframework.org/schema/aop"  
  4.         xmlns:tx="http://www.springframework.org/schema/tx"  
  5.         xmlns:context="http://www.springframework.org/schema/context"  
  6.         xmlns:p="http://www.springframework.org/schema/p"  
  7.         xmlns:mvc="http://www.springframework.org/schema/mvc"  
  8.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  9.         xsi:schemaLocation="  
  10.         http://www.springframework.org/schema/beans  
  11.         http://www.springframework.org/schema/beans/spring-beans.xsd  
  12.         http://www.springframework.org/schema/aop  
  13.         http://www.springframework.org/schema/aop/spring-aop.xsd  
  14.         http://www.springframework.org/schema/tx  
  15.         http://www.springframework.org/schema/tx/spring-tx.xsd  
  16.         http://www.springframework.org/schema/context  
  17.         http://www.springframework.org/schema/context/spring-context.xsd  
  18.          http://www.springframework.org/schema/mvc  
  19.         http://www.springframework.org/schema/mvc/spring-mvc.xsd  
  20. ">  
  21.     <!--配置 包 掃描器-->  
  22.     <context:component-scan base-package="cn.hello.Valldator"/>  
  23.   
  24.     <bean id="myValltor" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">  
  25.         <property name="providerClass" value="org.hibernate.validator.HibernateValidator"></property>  
  26.     </bean>  
  27.   
  28.    <mvc:annotation-driven validator="myValltor"></mvc:annotation-driven>  
  29.   
  30. </beans>  
  1. <h1>數據校驗</h1>  
  2. <form action="/first" method="post">  
  3.     成績:<input name="score" /> <span>${scoremsg }</span><br/><br/>  
  4.     姓名:<input name="name"/><span>${namemsg }</span><br/><br/>  
  5.     電話:<input name="phone"/><span>${phonemsg }</span><br/><br/>  
  6.     <input type="submit" value="註冊"/>  
  7. </form>  
  1. <body>  
  2.    歡迎你  
  3. </body>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章