DateTimeFormat注解

    xiaoxiao2021-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)