[英]Can't convert type: value: java.sql.Timestamp to org.joda.time.DateTime
[英]Cannot convert of type class java.sql.Timestamp to class org.joda.time.DateTime
在windows 7
平台上使用jdk-1.7.0_51
和tomcat-7.0.42
在以下位置我的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
初始化,並且並非在所有環境中都發生。
還嘗試將<fmt:formatDate...
替換為<joda:format ...
標記,但又出現另一個錯誤:
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.