簡體   English   中英

無法將類型類java.sql.Timestamp轉換為類org.joda.time.DateTime

[英]Cannot convert of type class java.sql.Timestamp to class org.joda.time.DateTime

windows 7平台上使用jdk-1.7.0_51tomcat-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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM