0

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

<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...with <joda:format ...tag 但又出现了一个错误:

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

1 回答 1

1

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>
于 2014-01-27T10:34:09.977 回答