2010-12-03 64 views

回答

4

至於時間表示,最方便的類型應該是Joda Time's LocalTime
map the LocalTime type to the database有幾種轉換器可供使用。

您需要JAR包joda-time and joda-time-hibernate。然後

你的域類可能是這樣的:

import org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime 
import org.joda.time.LocalTime 

class TimeDomain { 
    LocalTime localTime 

    static mapping = { 
     localTime type: PersistentLocalTimeAsTime 
    } 

    // business logic would belong to a service class 
    LocalTime plusMinutes(int minutes) { 
     localTime.plusMinutes(minutes) 
    } 
} 
相關問題