如何将日期字符串格式为yyyy-MM格式转换为带有休眠annoation的日期 [英] How Can I convert Date String as format yyyy-MM to Date with hibernate annoation
本文介绍了如何将日期字符串格式为yyyy-MM格式转换为带有休眠annoation的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试在我的属性顶部使用 @DateTimeFormat(patter =yyyy-MM)
时,
错误:org.hibernate.engine.jdbc.spi.SqlExceptionHelper - 格式错误
for DATE'2015-05'
我能做些什么来解决这个问题?
解决方案
yyyy-MMM,yyyy-MM-dd全部正常工作。 @DateTimeFormat不支持yyyy-MM格式。然后,为了解决这个问题,我需要在getter和setter中使用attributeConverter或者wave魔术
When I tried to use @DateTimeFormat(patter="yyyy-MM")
at top of my attribute,
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Bad format for DATE '2015-05'
What Can I do to solve this problem?
解决方案
As I test, format lick "yyyy-MMM", "yyyy-MM-dd" all working. The "yyyy-MM" format is not supported by @DateTimeFormat. Then, for getting around, I need attributeConverter or wave magic in getter and setter
这篇关于如何将日期字符串格式为yyyy-MM格式转换为带有休眠annoation的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文