1,DateTimeFormat注解
我们可以使用@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>
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
2.需要启动mvc中的注解驱动 <mvc:annotation-driven />
xmlns:mvc="http://www.springframework.org/schema/mvc"
http://www.springframework.org/schema/mvc
<mvc:annotation-driven></mvc:annotation-driven>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date birthday;
负值时输入1233-23-23这样一个字符串,
DateTimeFormat会将它转换成Date对象
浙公网安备 33010602011771号