Grails脚手架链接参考问题
我正在为两个域类的几个控制器使用脚手架:1 个扇区到 N 个项目:
class Item {
String name
static belongsTo = [sector:Sector]
....
}
class Sector {
String name
static hasMany = [items:Item]
....
}
当我生成相应的脚手架控制器时,我使用了模式(类)mgr:Sectormgr.groovy 和 Itemmgr.groovy。
问题是某些链接在某些生成的视图中无效,因为它假设 I 遵循控制器的默认名称。例如:
- 如果我转到 /sectormgr/show/20,与其关联的项目列表具有链接 /item/show/22,而不是 /itemmgr/show/22
有一个简单的解决方案吗?创建控制器时我是否遗漏了一些东西?
提前致谢
I'm using scaffolding for a couple of Controllers for two Domain Classes: 1 Sector to N Items:
class Item {
String name
static belongsTo = [sector:Sector]
....
}
class Sector {
String name
static hasMany = [items:Item]
....
}
When I generated the corresponding scaffolding controllers I used the pattern (class)mgr: Sectormgr.groovy and Itemmgr.groovy.
The problem is that some links are invalid in some of the generated views, for it is assuming the I followed the default names for the controllers. For instance:
- if I go to /sectormgr/show/20, the list of items associated with it have the link /item/show/22, instead of /itemmgr/show/22
Is there an easy fix for this? Am I missing something when I create the controllers ?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信有几种方法可以解决这个问题。最简单的方法是坚持 Grails 命名控制器的约定 SectorController.groovy、ItemController.groovy 等。
我认为可以解决此问题的另一种方法是更新 grails-app/conf /UrlMappings.groovy。这是默认的脚手架:
您想要类似的东西:
There's a couple ways to address this I believe. The simplest is to stick to Grails' convention of naming your controllers SectorController.groovy, ItemController.groovy, etc.
One other way to handle this that I think will work is to update your grails-app/conf/UrlMappings.groovy. Here is the default scaffolding:
You want something like:
更改 URLMappings 似乎对我不起作用,而且这是一个更全局的更改。我采取的方法是运行 intall-templates 并更改 src/templates/scaffolding/show.gsp 中控制器的链接。
更改模板后,您需要重新启动服务器。
Changing the URLMappings didn't seem to work for me, and it's a much more global change. Running
intall-templates
and changing the links to controllers insrc/templates/scaffolding/show.gsp
was the approach I took.You'll need to restart your server after changing the template.