0

I try to fill a form with the values of System

  def edit(id: Long) = IsAuthenticated { username => implicit request =>
    User.findByEmail(username).map { user =>
      System.findById(id).map { system =>
      Ok(html.systems.editForm(id, systemForm.fill(system), Person.options, user))
    }.getOrElse(NotFound)
    }.getOrElse(Forbidden)
  }

but some of 'system' values are java.math.BigDecimal

 val systemForm = Form(
    mapping(
      "id" -> ignored(NotAssigned:Pk[BigDecimal]),
      "sys_name" -> nonEmptyText,
      "sys_desc" -> nonEmptyText,
      "sys_owner1_id" -> longNumber,
      "sys_owner2_id" -> optional(longNumber)
    )(System.apply)(System.unapply)
  )

and it says :

type mismatch; found : (anorm.Pk[java.math.BigDecimal], String, String, String, Option[String], java.math.BigDecimal, Option[java.math.BigDecimal]) => models.System required: (anorm.Pk[java.math.BigDecimal], String, String, Long, Option[Long]) => ? 

how can i handle this?

4

1 回答 1

0

看起来像异常或附近的问题。

正如您从错误描述中看到的那样,sys_owner1_id并且在查询结果sys_owner2_id中是BigIntegers,但long在表单中声明。

我不熟悉 anorm,但解决方案是在 anorm 中声明这些 id,或者将它们声明为BigInteger表单映射或在您的查询中转换BigInteger为。long

于 2013-09-05T01:31:07.293 回答