class InstitutionController extends Controller {
def updateInstitution = Action { implicit request =>
{
request.body.asJson.get.validate[GallreyJsonValidationForUpdate].fold(
valid = {
updateInstitution =>
{
Redirect(routes.GalleryController.updateGallreyObject()).flashing("uuid"- >updateInstitution.uuid,"institutionName"->updateInstitution.institutionName,"details"->updateInstitution.details)
}
},
invalid = {
errors =>
{
val json=commonUtils.getResponse(Http.Status.BAD_REQUEST, ServerResponseMessages.VALIDATION_FAILED,JsError.toJson(errors))
log.error("sending error in json{}", json)
BadRequest(json)
}
})
}
}
这是我重定向到
的动作class GalleryController extends Controller {
def updateGallreyObject = Action { implicit request =>
{
val uuid=request.flash.get("uuid")
val institutionName=request.flash.get("institutionName")
val details=request.flash.get("details")
Ok("some details")
}}
}
这是我正在使用的卷曲文件
contentType="Content-type: application/json";
data='{ "uuid" : "123" , "institutionName" : "abc" , "details" : "some details"
}';
echo " "
echo "------------------ Sending Data ------------------"
echo " "
echo "Content-Type : " $contentType
echo "Data : " $data
echo " "
echo "------------------ Response ------------------"
echo " "
echo " "
curl --include --request POST --header "Content-type: application/json" --data "$data" http://localhost:9000/institution/update
我得到的回应是
HTTP/1.1 303 See Other
Location: /gallery/update
Set-Cookie: PLAY_FLASH=uuid=123 &institutionName=abc&details=some+details; Path=/; HTTPOnly
Date: Sat, 04 Mar 2017 14:40:29 GMT
Content-Length: 0
这是路线
POST /institution/update controllers.InstitutionController.updateInstitution
为什么它没有重定向到updateGallreyObject
动作?我做错了什么请帮助,我希望它重定向到updateGallreyObject
动作与数据请帮助,我期待这个回应“一些细节”
更新我已经有了这条路线
POST /gallery/update controllers.GalleryController.updateGallreyObject
答案 0 :(得分:0)
因为您需要路线中updateGallreyObject
的映射。
GET /galery controllers.GalleryController.updateGallreyObject
P.S。在将代码发布到此处之前重新格式化代码。您可能希望使用外部格式化程序,如Scalariform或Scalafmt。
答案 1 :(得分:0)
尝试使用match
但fold
,就像在文档中一样:https://www.playframework.com/documentation/2.3.x/ScalaJsonCombinators#Putting-it-all-together
request.body.asJson.get.validate[GallreyJsonValidationForUpdate] match {
case s: JsSuccess[GallreyJsonValidationForUpdate] => {
val updateInstitution: GallreyJsonValidationForUpdate = s.get
Redirect(routes.GalleryController.updateGallreyObject()).flashing("uuid"- >updateInstitution.uuid,"institutionName"->updateInstitution.institutionName,"details"->updateInstitution.details)
}
case e: JsError => {
val json=commonUtils.getResponse(Http.Status.BAD_REQUEST, ServerResponseMessages.VALIDATION_FAILED,JsError.toJson(errors))
log.error("sending error in json{}", json)
BadRequest(json)
}
}