首页
IT
登录
6mi
u
盘
搜
搜 索
IT
DateTimeFormat注解
DateTimeFormat注解
xiaoxiao
2021-12-14
18
我们可以使用@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>
转载请注明原文地址: https://ju.6miu.com/read-972019.html
专利
最新回复
(
0
)