对于同一控制器,Grails 使用不一致的重定向 uri
我的 Grails 应用程序中有一个简单的控制器,具有简单的映射...
TCacheController {
def index ={}
def list= {}
}
"/tcache/" (controller: "TCache"){
action = [GET: "index"]
}
"/tcache/items" (controller: "TCache"){
action = [GET: "list"]
}
我的所有 URL 均采用 http: //.../tcache/*,一切正常。当我在这样的视图中使用
时,就会出现问题...
<g:form controller="TCache">
<g:actionSubmit class="delete" action="list" value="List Items">
提交有效,但在我的列表操作中,我有一个重定向,以防出现问题,并且该重定向是导致 404,因为 Grails 正在发送到 /TCache/..
,而不是 /tcache/...
在什么情况下 Grails 会更改 URI 的大小写,以及有没有办法强制它始终使用/tcache
?我尝试在表单中使用controller=“tcache”,但随后操作停止工作,可能是因为Grails 找不到控制器。
I've got a simple controller in my Grails app with simple mappings...
TCacheController {
def index ={}
def list= {}
}
"/tcache/" (controller: "TCache"){
action = [GET: "index"]
}
"/tcache/items" (controller: "TCache"){
action = [GET: "list"]
}
All of my URL's are of the form http://.../tcache/*, and everything works fine. The problem arises when I use <g:actionSubmit>
in a view like this...
<g:form controller="TCache">
<g:actionSubmit class="delete" action="list" value="List Items">
The submit works, but in my list action I have a redirect in case something goes wrong, and that redirect is resulting in 404 because Grails is sending to /TCache/..
, not /tcache/...
Under what circumstances is Grails changing upper/lower case of the URI, and is there a way to force it to always use /tcache
? I tried using controller="tcache" in the form, but then the action stops working, probably because Grails can't find the controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己设法解决了这个问题。 Grails 的约定优于配置非常棒,但有时 Grails 并不总是能够正确猜测。
在控制器中,渲染视图时,使用文字路径可确保 Grails 不必猜测任何内容...
而不是...
在我的情况下,有多个控制器,看来 Grails 有点困惑并尝试添加前缀
/TCache/..
用于本应使用/tcache/listitems
的完整渲染视图路径。I managed to figure this out on my own. Grails' convention over configuration is great, but sometimes Grails does not always guess correctly.
In the controller, when rendering a view, using literal paths ensures that Grails will not have to guess anything...
instead of...
In my case, having multiple controllers, it appears Grails got a bit confused and attempted to prefix
/TCache/..
for the full render view path when it should have used/tcache/listitems
.