playframework表单映射日期和时间

时间:2015-05-04 21:11:45

标签: forms date playframework mapping

我有一个看起来像这样的案例类(DateTime是org.joda.time.DateTime一个):

case class Match (  
  var date: DateTime,
  var tournament: Option[String] = None,
  var _links: Link
)

对于我的JSon Rest服务,我将其映射为:

  implicit val matchReader: Reads[Match] = (
    (JsPath \ "date").read[DateTime] and
    (JsPath \ "tournament").readNullable[String] and
    (JsPath \ "_links").read[Link]
  )(Match.apply _)

  implicit val matchWriter: Writes[Match] = (
    (JsPath \ "date").write[DateTime] and
    (JsPath \ "tournament").writeNullable[String] and
    (JsPath \ "_links").write[Link]
  )(unlift(Match.unapply))

对于我的表单,我将其映射为:

  val matchMapping = mapping(
      "date" -> jodaDate,
      "tournament" -> optional(text),
      "_links"   -> linkMapping
    )(Match.apply)(Match.unapply)

但我的老板要我在表单上显示两个单独的字段,一个用于Date,另一个用于Time,但是要将值存储在我的case类的单个成员中,因为它代表输出对象用于将数据存储在数据库中的Rest服务。

我该怎么做?

由于

0 个答案:

没有答案