有时候我们经常需要在页面添加日期等相关信息,此时需要制定日期格式化转换器,此操作非常简单:只需要在单独的属性上添加@DateTimeFormat注解即可,制定对应的格式
![](https://img-blog.csdnimg.cn/img_convert/1ff38ab30cb7178681ae89a7b2665e7b.png)
index.jsp
![](https://img-blog.csdnimg.cn/img_convert/3d2803fe7d6477aa36bf0ddeab77d5ff.png)
contorller层
![](https://img-blog.csdnimg.cn/img_convert/310a318154d83062216ce7aca008faeb.png)
springmvc.xml文件
![](https://img-blog.csdnimg.cn/img_convert/7152030ea486dd1c702cfe522d9f213a.png)
此时运行发现是没有问题的,但是需要注意的是,如果同时配置了自定义类型转换器之后,那么日期格式转化是有问题的。
![](https://img-blog.csdnimg.cn/img_convert/ea1c3d50e3216a646089bbe34ba4e423.png)
原因就在于ConversionServiceFactoryBean对象中有且仅有一个属性converters,此时可以使用另外一个类来做替换FormattingConversionServiceFactoryBean
![](https://img-blog.csdnimg.cn/img_convert/dab233501e829ea7b2413660916bc652.png)