【发布时间】:2016-06-23 09:40:27
【问题描述】:
我正在使用带有 Reactive mongo 驱动程序的 play-framework。为了在我们的路由文件中处理响应式 mongo BSONObjectId,我正在创建以下活页夹:
object StringToBSONObjectIdBinder {
/* This is for Path Parameter*/
implicit object pathBindableBSONObjectID extends play.api.mvc.PathBindable.Parsing[BSONObjectID](
BSONObjectID(_), _.stringify,
(key: String, e: Exception) =>
"Cannot parse parameter %s as BSONObjectID: %s".format(key, e.getMessage))
/* This is for query String*/
implicit object queryStringBindableBSONObjectID extends play.api.mvc.QueryStringBindable.Parsing[BSONObjectID](
BSONObjectID(_), _.stringify,
(key: String, e: Exception) =>
"Cannot parse parameter %s as BSONObjectID: %s".format(key, e.getMessage))
}
在路由中,我很容易将我的 id 路由为路径参数,如下例所示:
GET /company/:companyId/users-detail controllers.CompanyController.userDetail(companyId: BSONObjectID)
我的BSONObjectId 很容易与我的请求处理程序路径参数映射。但是当我在上述路线之后使用以下路线时:
GET /company/detail controllers.CompanyController.companyDetail
我正在关注BadRequest:
For request 'GET /company/detail?t=1466673779753' [Cannot parse parameter companyId as BSONObjectID: wrong ObjectId: 'teams']
但是当我如下切换路线时:
GET /company/detail controllers.CompanyController.companyDetail
GET /company/:companyId/users-detail controllers.CompanyController.userDetail(companyId: BSONObjectID)
服务运行成功。我仍然不知道实际问题是什么。这是播放框架问题,还是我的代码有问题?
【问题讨论】:
标签: scala playframework-2.3 reactivemongo play-reactivemongo