Controller接受的参数为日期类型。

1. 接受的参数为日期类型

Controller接受的参数为日期类型。

 

1.在UsersControllter.java中

 

1 @RequestMapping("toDate.do")
2     public String toDate(Date date) {
3         System.out.println(date);
4         return "index";
5     }


 

1  @InitBinder
2      public void initBinder(ServletRequestDataBinder binder){
3          //只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型
4          binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),
5                true));
6     }

 

Controller接受的参数为日期类型。

 

1 @RequestMapping("register.do")
2     public String register(Users users) {
3         System.out.println(users);
4         return "index";
5     }

2.bean 下的 Users.java 中

Controller接受的参数为日期类型。

 

 1 package com.zhiyou100.wc.bean;
 2 
 3 import java.util.Date;
 4 
 5 import org.springframework.format.annotation.DateTimeFormat;
 6 
 7 public class Users {
 8     private String uname;
 9     private String password;
10     private String sex;
11     private int age;
12     private String address;
13     private String phone;
14     @DateTimeFormat(pattern="yyyy-MM-dd")
15     private Date brithday;
16     
17     public Date getBrithday() {
18         return brithday;
19     }
20     public void setBrithday(Date brithday) {
21         this.brithday = brithday;
22     }
23     public String getUname() {
24         return uname;
25     }
26     public void setUname(String uname) {
27         this.uname = uname;
28     }
29     public String getPassword() {
30         return password;
31     }
32     public void setPassword(String password) {
33         this.password = password;
34     }
35     public String getSex() {
36         return sex;
37     }
38     public void setSex(String sex) {
39         this.sex = sex;
40     }
41     
42     public int getAge() {
43         return age;
44     }
45     public void setAge(int age) {
46         this.age = age;
47     }
48     public String getAddress() {
49         return address;
50     }
51     public void setAddress(String address) {
52         this.address = address;
53     }
54     public String getPhone() {
55         return phone;
56     }
57     public void setPhone(String phone) {
58         this.phone = phone;
59     }
60     @Override
61     public String toString() {
62         return "Users [uname=" + uname + ", password=" + password + ", sex=" + sex + ", age=" + age + ", address="
63                 + address + ", phone=" + phone + ", brithday=" + brithday + "]";
64     }
65     public Users(String uname, String password, String sex, int age, String address, String phone, Date brithday) {
66         super();
67         this.uname = uname;
68         this.password = password;
69         this.sex = sex;
70         this.age = age;
71         this.address = address;
72         this.phone = phone;
73         this.brithday = brithday;
74     }
75     public Users() {
76         super();
77         // TODO Auto-generated constructor stub
78     }
79     
80     
81 }

 

上一篇:JavaScript高级


下一篇:Linux基本命令