1
我正在研究最近使用百里香作爲視圖引擎的spring mvc web應用程序,用於dao和spring安全性的hibernate。使用彈簧轉換器
,當我讓我的控制器,I面臨的情況:
我有一個Notification
實體,其具有化合物主鍵NotificationPK(CreationDate+UserID)
:creationDate是創建通知之時間
我想使用網址/notif/{creationDate}顯示通知的內容。 (我並不需要通過用戶ID,因爲我可以使用Spring Security的檢索)
問題是創建日期是時間戳,所以我必須使用Spring的轉換器(有人告訴我的話)
但事情是,我得到的轉換器的一般想法,但我不知道如何使它在這種情況下,我不明白這個轉換器如何在控制器工作
有人可以請幫忙關於如何將該轉換器添加到控制器的示例和解釋,以及該轉換器如何工作
編輯
這是正確的代碼:
@RequestMapping(value = "/doctor/notification/{creationDate}")
public ModelAndView getNotification(@PathVariable("creationDate") @org.springframework.format.annotation.DateTimeFormat(pattern = "YYYY-mm-dd HH:mm:ss") Timestamp creationDate){
if (doctor==null) setCurrentUser();
if (creationDate==null) throw new NoSuchNotificationException();
NotificationPK pk = new NotificationPK();
pk.setRecipient(doctor.getIdPers());
pk.setCreationDate(creationDate); //.....
的creationdate實際上包含的時間太長(我會編輯) – Aissasa 2014-09-04 13:08:30
請檢查以上代碼 – Aissasa 2014-09-04 13:52:09
我相信這適用於日曆和日期,所以我不確定Timestamp。你可以試試看看會發生什麼。 – 2014-09-04 17:36:56