Spring里用@RequestParam接受Date类型的url参数

首先引入joda-time包。maven的dependency:

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.4</version>
        </dependency>

在Controller代码里:

public String testMethod(@RequestParam @DateTimeFormat(pattern="yyyy-MM-dd") Date testdate){
    System.out.println(testDate);
}

注意用pattern来规定日期的格式。

测试的url:

?testdate=2014-09-04

posted @ 2014-09-05 17:59  戴仓薯  阅读(15250)  评论(0编辑  收藏  举报