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

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

 

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     }

 

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10     <a href="user/register.do?name=zs">链接到List.do</a>
11     
12     <form action="user/register.do" method="post">
13     姓名:<input type="text" name="uname"/><br>
14     密码:<input type="text" name="password"/><br>
15     性别:<input type="text" name="sex"/><br>
16     年龄:<input type="text" name="agee"/><br>
17     地址:<input type="text" name="address"/><br>
18     手机:<input type="text" name="phone"/><br>
19         <input type="submit" value="提交"/>
20     </form>
21     
22 </body>
23 </html>

 

 

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

2.bean 下的 Users.java 中

 

 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 }

 

转载于:https://www.cnblogs.com/banzhuanlaowang/p/11455972.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值