简体   繁体   English

如何处理ibatis映射中的空日期

[英]how to cope with a null Date in an ibatis mapping

I have the following in one of my result mappings. 我的一个结果映射中包含以下内容。

<result property="updateDate" column="update_date" javaType="java.util.Date"
jdbcType="DATE" nullValue="01/01/1900"/>

basically updateDate is a setter that accepts Date . 基本上updateDate是一个接受Date的setter。 However, sometimes updateDate will be null in the database. 但是,有时updateDate在数据库中将为null In those cases I want to have a default date of 01/01/1900 . 在这些情况下,我希望默认日期为01/01/1900

However, the above mappings gives me the following error when updateDate is null from DB 但是,当数据库中的updateDate为null时,上述映射给我以下错误

Cause: java.lang.RuntimeException: Error setting property 'setUpdateDate'

Is the problem that your nullValue="01/01/1900" is trying to pass a string into updateDate setter? 是否存在您的nullValue =“ 01/01/1900”试图将字符串传递到updateDate setter的问题? If you took that out, I assume the setter would be called by iBatis with 'null' and then you could apply the default in your setter in the Java code. 如果您将其删除,我假设iBatis将使用null调用设置器,然后可以在Java代码中将默认值应用到设置器中。

Can you change your updateDate method to take a null and set the "01/01/1900" Date in there? 您可以将updateDate方法更改为null并在其中设置“ 01/01/1900”日期吗?

This message can also occur when the setter doesn't exist or is spelled incorrectly too, make sure that's not the case. 当二传手不存在或拼写不正确时,也会出现此消息,请确保不是这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM