gpt4 book ai didi

grails - 如何在 Grails 中隐藏 URL 参数

转载 作者:行者123 更新时间:2023-12-01 17:54:37 24 4
gpt4 key购买 nike

当用户创建新的 Load 对象时,如果用户选中“Paid On Delivery”复选框,那么他们将在创建新的 Load 对象后立即重定向到 Payment Controller 新的 Load 已创建。创建新的 Load 所需的几个参数也用于创建新的 Payment,因此我只需在重定向中传递参数,如下所示:

redirect(controller: "payment", action: "create", params: params)

这工作正常,但它给了我一个真正令人讨厌的 URL,其中包含所有参数。 如何将我的参数传递给另一个 Controller 并防止它们出现在 URL 中?

更新:

我应该说,我很感谢大家针对这么一个小问题提出的建议。即使有所有建议,最好的方法似乎仍然是我想要避免的方法,即在 redirect 调用中手动构建参数映射。这没什么大不了的,特别是因为只有几个参数,我只是不相信没有更干净、更自动化的方法来解决这个问题。

    def loadInstance = new Load(params)

if (loadInstance.save(flush: true)) {
Account.get(params.account.id).balance -= new BigDecimal(params.transactionAmount)
flash.message = "${message(code: 'default.created.message', args: [message(code: 'load.label', default: 'Load'), loadInstance.id])}"
if(params.paidOnDelivery){
redirect(
controller: "payment",
action: "create",

//There has to be a better way than this. Just writing "params:params" results in the values being wrapped in double quotes once they get to the Payment controller. If it wasn't for that then "params:params" would work great and I would not of had to ask this question :)
params: [
"account.id":params.account.id,
"dateOfTransaction":params.dateOfTransaction,
"dateOfTransaction_year":params.dateOfTransaction_year,
"dateOfTransaction_month":params.dateOfTransaction_month,
"dateOfTransaction_day":params.dateOfTransaction_day,
"dateOfTransaction_hour":params.dateOfTransaction_hour,
"dateOfTransaction_minute":params.dateOfTransaction_minute,
"transactionAmount":params.transactionAmount
]
)
return
}
redirect(action: "show", id: loadInstance.id)
}
else {
render(view: "create", model: [loggedByUsers:loggedByUsers, accounts:accounts, cargoProviders:cargoProviders, deliveredByUsers:deliveredByUsers, loadInstance:loadInstance])
}

最佳答案

您可以执行服务器端转发而不是重定向。只需替换:

redirect(controller: "payment", action: "create", params: params)

与:

forward(controller: "payment", action: "create", params: params)

更新

要解决您在评论中描述的刷新问题,请使您转发的操作发送重定向(而不是呈现 View ),例如

class PaymentController {

def create = {

Integer paymentId = // Create a payment and get it's ID
redirect(action: 'show', id: paymentId)
}

def show = {
def id = params.id
// show the payment with this ID
}
}

关于grails - 如何在 Grails 中隐藏 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7764042/

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