无法将类型类 java.sql.Timestamp 转换为类 org.joda.time.DateTime



使用jdk-1.7.0_51tomcat-7.0.42windows 7平台上我的JSP页面:

<fmt:formatDate value='${abtest.modifiedDate}' pattern="yyyy-MM-dd HH:mm:ss"/>

其中abtest.modifiedDate属性的类型为java.util.Date并使用java.sql.Timestamp实例进行初始化。

引发以下异常:

javax.servlet.jsp.JspException: javax.el.ELException: Cannot convert 1/24/14 4:31 PM of type class java.sql.Timestamp to class org.joda.time.DateTime

该错误似乎很奇怪abtest.modifiedDate因为该属性未使用org.joda.time.DateTime初始化,并且并非在所有环境中都发生。

还尝试用<joda:format ...标签替换:<fmt:formatDate...,但得到另一个错误:

javax.servlet.jsp.JspException: javax.servlet.jsp.JspException: value attribute of format tag must be a ReadableInstant or ReadablePartial, was: java.sql.Timestamp

将此批注添加到实体类的DateTime字段中

@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
private DateTime birthDay;

在你的JSP中,继续使用joda format tag

<c:set var="formattedDateTimeValue">
<joda:format value="${DateTimeValue}" pattern="dd.MM.yyyy" />
<!-- Or any pattern you want -->
</c:set>

相关内容

最新更新