【问题标题】:Play! error overloaded method value mapping with alternatives?玩!错误重载方法值映射与替代方案?
【发布时间】:2012-04-10 12:03:40
【问题描述】:

在我的 Play 中定义一个表单!当编译器吐出这个奇怪的错误时控制器:overloaded method value mapping with alternative:...[a bunch of crap]...Error occurred in an application involving default arguments

这是代码,我不确定是什么原因:

 val jobForm: Form[Job] = Form(
    mapping(
      "id" -> of[Long],
      "end_time" -> text(minLength = 3),
      "start_time" -> text(minLength = 3),
      "client_id" -> of[Long],
      "start_address_type" -> text,
      "start_address" -> text(minLength = 3),
      "start_city" -> text(minLength = 3),
      "start_province" -> text(minLength = 2),
      "start_lat" -> optional(text),
      "start_lng" -> optional(text),
      "comments" -> text,
      "created" -> text,
      "modified" -> text,
      "canceled" -> of[Boolean],
      "started" -> of[Boolean],
      "completed" -> of[Boolean],
      "user_id" -> optional(of[Long]),
      "start_order" -> optional(number),
      "end_order" -> optional(number),
      "account_id" -> of[Long]
    )(Job.apply)(Job.unapply)
  )

【问题讨论】:

    标签: scala playframework-2.0


    【解决方案1】:

    看过剧本! 2.0 源码。看起来每个mapping() 最多只能有 18 个参数,所以我不得不开始嵌套并创建新的案例类。结果如下:

    val jobForm: Form[JobSimple] = Form(
        mapping(
          "id" -> of[Long],
          "end_time" -> text(minLength = 3),
          "start_time" -> text(minLength = 3),
          "client_id" -> of[Long],
          "location" -> mapping(
            "start_address_type" -> text,
            "start_address" -> text(minLength = 3),
            "start_city" -> text(minLength = 3),
            "start_province" -> text(minLength = 2),
            "start_lat" -> optional(text),
            "start_lng" -> optional(text)
            )(JobLocation.apply)(JobLocation.unapply),
          "comments" -> text,
          "created" -> text,
          "modified" -> text,
          "canceled" -> of[Boolean],
          "started" -> of[Boolean],
          "completed" -> of[Boolean],
          "user_id" -> optional(of[Long]),
          "start_order" -> optional(number),
          "account_id" -> of[Long]
        )(JobSimple.apply)(JobSimple.unapply)
      )
    

    【讨论】:

    • 是的,我不知道他们为什么不支持案例类的 22 个字段的限制。
    猜你喜欢
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    相关资源
    最近更新 更多