【问题标题】:Action is not redirecting to another Action in play-framework动作没有重定向到播放框架中的另一个动作
【发布时间】:2017-07-24 15:59:39
【问题描述】:
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")
 }}
}

这是我正在使用的 curl 文件

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 Action ?我做错了什么请帮忙,我希望它重定向到updateGallreyObject 数据操作请帮忙,我期待这个回复“一些细节”

更新我已经有了这条路线

POST   /gallery/update                                  controllers.GalleryController.updateGallreyObject

【问题讨论】:

    标签: scala playframework playframework-2.2 playframework-2.3


    【解决方案1】:

    因为您需要在路由中为您的updateGallreyObject 映射。

    GET /galery                    controllers.GalleryController.updateGallreyObject
    

    附:在此处发布之前重新格式化您的代码。您可能想要使用外部格式化程序,例如 Scalariform 或 Scalafmt。

    【讨论】:

      【解决方案2】:

      尝试使用matchfold,就像在文档中一样: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)
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-22
        相关资源
        最近更新 更多