事件类定义
class event extends MongoRecord[event] with MongoId[event]{
def meta = event
object title extends StringField(this, 70)
object description extends StringField(this, 200)
object date_time extends DateTimeField(this)
object email extends StringField(this, 70)
object placeName extends StringField(this, 70)
object placeLat extends DoubleField(this)
object placeLon extends DoubleField(this)
object placeCity extends StringField(this, 100)
}
object event extends event with MongoMetaRecord[event]
从文本中存储日期:
val event_temp = event.createRecord
val cal = Calendar.getInstance()
val dashDate = new SimpleDateFormat("yyyy/MM/dd HH:mm")
cal.setTime(dashDate.parse(String))
event_temp.date_time(cal)
event_temp.save
获取事件和排序
val events= event.findAll
events.sortWith(_.date_time.is before _.date_time.is)
events 是 List[event],而 date_time.is 返回 java.util.Calendar。它返回未排序的 List[event]。