Listing 21-24. The AbstractBlogPosting Class
package com.apress.prospring3.springblog.domain;
// Import statements omitted
@MappedSuperclass
@Audited
public abstract class AbstractBlogPosting implements BlogPosting, Auditable<String, Long>,
Serializable {
protected
Long id;
protected
String subject;
protected
String body;
protected
DateTime postDate;
protected
String createdBy;
protected
DateTime createdDate;
protected
String lastModifiedBy;
protected
DateTime lastModifiedDate;
protected
int version;
@Column(name = "CREATED_DATE")
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
@DateTimeFormat(iso=ISO.DATE_TIME)
public DateTime getCreatedDate() {
return this.createdDate;
}
@Column(name = "LAST_MODIFIED_DATE")
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
@DateTimeFormat(iso=ISO.DATE_TIME)
public DateTime getLastModifiedDate() {
return this.lastModifiedDate;
}
// Other code omitted
}
In Listing 21-24, the date-time format annotations are highlighted in bold. For the createdDate and
lastModifiedDate properties, the annotation is applied, and the type ISO.DATE_TIME format is used,
which corresponds to the format yyyy-MM-dd'T'hh:mm:ss.SSSZ (for example, 2012-01-
30T13:53:52.324+08:00). This is because for the create date and last modified date, we also want to know
the time in addition to the date. Note that Spring supports the formatting of JodaTime's DateTime type
out of the box.
Figure 21-20 shows the view page of a blog post entry in SpringBlog, and in the figure, you can see
the conversion and formatting in action.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home