grails重定向错误
控制器中 grails 中的重定向问题。
在Controller中:
def function1 = {
... do stuff ...
... go to service ...
redirect(action: "searchName", name: test)
//redirect(action: "searchName", params: [ name: test ])
}
在searchName中,没有参数。它是一个空列表。 尝试调用重定向的第二种方法,对于确实存在的方法,我得到了 grails 异常(MissingMethodException)。
我没有看到什么特别的事情,这正在发生。
有什么帮助吗?
编辑
MissingMethodException 不在 searchName 函数上,而是在服务内的方法上。这个方法是有的。
如果我使用第一个重定向方法,则服务方法可以正常工作,但到 searchName 的重定向包含空参数。 如果我切换重定向方法,那么服务方法将不再起作用 (例外,所以它永远不会到达重定向)。具有完全重新编译/清理的代码。
另外,searchName 是一个闭包。再说一遍,没什么特别的。 获取名称参数并使用它。
class MyWierdController {
def function1 = {
... do stuff ...
... go to service ...
String test="blah"
redirect(action: "searchName", name: test)
}
def searchName = {
if (params.name) {
log.info "its there"
} else {
log.info "its not there"
}
}
}
problem with redirection in a grails in a controller.
in Controller:
def function1 = {
... do stuff ...
... go to service ...
redirect(action: "searchName", name: test)
//redirect(action: "searchName", params: [ name: test ])
}
in searchName, there are no parameters. its an empty list.
try the second way of calling the redirect and i get grails exceions (MissingMethodException), for a method that does exist.
there is nothing special that i can see, that is going on.
any help?
EDIT
the MissingMethodException is not on the searchName function, but on a method within the service. this method is there.
if i use the first redirect method, then the service method works correctly, but the redirect to searchName contains empty parameters.
if i switch the redirect method, then the service method no longer works
(with the exception, so it never gets to the redirect). with fully recompiled/cleaned code.
also, searchName is a closure. again, nothing fancy.
grab the name parameter, and work with it.
class MyWierdController {
def function1 = {
... do stuff ...
... go to service ...
String test="blah"
redirect(action: "searchName", name: test)
}
def searchName = {
if (params.name) {
log.info "its there"
} else {
log.info "its not there"
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
redirect()
是真正的 HTTP 重定向。您将遇到问题,因为所有参数都将被序列化和反序列化,并且可能会丢失类型信息(例如日期,重定向后将是字符串)。第一个版本将忽略名称参数,因为所有参数都必须在
由于您没有引用参数,groovy 期望它们是一个变量并尝试解析它们,因为两者都未定义,因此它变成了
params: [null: null] 不过
我猜,那。您正在搜索
render(view: "searchName", params: ["name": "test"])
,它不会执行 HTTP 重定向。redirect()
is a real HTTP redirect. You will have issues, because all your params will be serialized an deserialized and probably you are losing type information (e.g. Date, which will be string after the redirect.The first version will ignore name parameter, since all parameters have to be within
params
.Try
Since you did not quoted the parameters, groovy expects them to be a variable and tries to resolve them. Since both are undefined it is becoming
params: [null: null]
.However I guess, that you are searching for
render(view: "searchName", params: ["name": "test"])
, which will not do a HTTP redirect.