gpt4 book ai didi

java - 如何重定向到在 play 框架中有 post 方法的 Action

转载 作者:太空宇宙 更新时间:2023-11-04 12:24:38 25 4
gpt4 key购买 nike

case class ResetPasswordJsonValidation (id : String ,email : String)

object ResetPasswordJsonValidation {

implicit val resetPasswordRead : Reads[ResetPasswordJsonValidation]= (
(JsPath \ "email").read(email) and
(JsPath \ "id").read(id))
(ResetPasswordJsonValidation.apply _)
}

def resetPassword = Action {
request =>
request.body.asJson.get.validate[ResetPasswordJsonValidation].fold(

resetPassword =>
{
log.info("id is {}" ,resetPassword.id)
log.info("email id is {}" ,resetPassword.email)
}
)
}

在路由文件中

POST   /direct-user/reset-password                      controllers.DirectUserController.resetPassword

这是我用来访问此路线的curl 文件

#!/bin/bash

contentType="Content-type: application/json";

data='{ "id" : "54d3732d-d728-40d3-ae63-b18ab6be8e70" ,
"email":"bob@example.com"}';
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//direct-user/reset-password

现在我想用代码执行此操作意味着我有一个操作 A,其中我需要重定向到 resetPasswordAction 我不知道该怎么做请帮助我

def A = Action {
var email:String="bob@example.com"
var id:String="54d3732d-d728-40d3-ae63-b18ab6be8e70"
Redirect(routes.DirectUserController.resetPassword())//how can i send email and id parameter to resetPassword as its getting from curl file
}

请帮忙

最佳答案

您可以直接调用该方法而不是通过路由对象来调用该方法,而不是重定向,

返回directController.resetPassword()

因为上下文对象(Request、Response、Session 是该线程的本地对象,因此您可以从请求对象获取这些参数)

关于java - 如何重定向到在 play 框架中有 post 方法的 Action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38498235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com