我正在尝试编写一个异步 PlayFramework 控制器来接收 POST 请求并在数据库中创建一个新对象:
def register = Action(BodyParsers.parse.json) { request =>
val businessInfoResult = request.body.validate[BusinessInfo]
businessInfoResult.fold(errors =>{
BadRequest(Json.obj("status"-> "Error", "message"->JsError.toJson(errors))) //Error on this line
}, businessInfo=> {
//save the object
Ok(Json.obj("status" ->"OK", "message" -> ("Place '"+ businessInfo.businessName +"' saved.") )) //Error on this line
})
}
但是,它不断抛出以下错误:
reference to Json is ambiguous; it is imported twice in the same scope by import play.libs.Json and import play.mvc.BodyParser.Json AsyncController.scala
错误在第 108 行和第 105 行抛出,它们对应于//Error on this line
上面注释的行(带有 BadRequest(..) 和 Ok(..) 的行)
我该如何解决这个问题?我可以使用 new JsValue(Map(..)) 但想知道是否还有其他方法。
非常感谢你的帮助。