DateTimeFormat注解

来源:互联网 发布:印度出口粮食知乎 编辑:程序博客网 时间:2024/06/05 17:20
我们可以使用@DateTimeFormat注解将一个字符串转成一个Date对象,可以使用在字段上也可以使用中方法中。如:  
public String test2(@RequestParam("uid") int id,@RequestParam(required=false,name="uage")Integer age,@DateTimeFormat(pattern="yyyy-MM-dd")Date date,UserInfo user) {}

但需要注意一下事项:
        1.需要导入
joda-time.jar包,maven的配置方式为:
                
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.6</version>
</dependency>
        2.需要启动
mvc中的注解驱动 <mvc:annotation-driven />
                
xmlns:mvc="http://www.springframework.org/schema/mvc"
                
http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 
                
                
<!-- 启用mvc中的注解驱动 -->
        <mvc:annotation-driven></mvc:annotation-driven>  
0 0