2

我正在为两个域类的几个控制器使用脚手架:1 个扇区到 N 个项目:

class Item {

String name

static belongsTo = [sector:Sector]

....

}

class Sector {

String name

static hasMany = [items:Item]

....

}

当我生成相应的脚手架控制器时,我使用了模式(类)mgr:Sectormgr.groovy 和 Itemmgr.groovy。

问题是某些链接在某些生成的视图中无效,因为它假设我遵循控制器的默认名称。例如:

  • 如果我转到 /sectormgr/show/20,与之关联的项目列表具有链接 /item/show/22,而不是 /itemmgr/show/22

有一个简单的解决方法吗?创建控制器时我是否遗漏了什么?

提前致谢

4

2 回答 2

0

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 in src/templates/scaffolding/show.gsp was the approach I took.

You'll need to restart your server after changing the template.

于 2010-03-20T19:54:07.530 回答
0

我相信有几种方法可以解决这个问题。最简单的是遵循 Grails 命名控制器 SectorController.groovy、ItemController.groovy 等的约定。

另一种我认为可行的处理方法是更新您的 grails-app/conf/UrlMappings.groovy。这是默认的脚手架:

class UrlMappings {
    static mappings = {
        "/$controller/$action?/$id?"{
            constraints {
                //apply constraints here
            }
        }
        "/"(view:"/index")
        "500"(view:'/error')
    }
}

你想要这样的东西:

class UrlMappings {
    static mappings = {
        "/${controller}mgr/$action?/$id?"{  //Add mgr after controller
            constraints {
                //apply constraints here
            }
        }
        "/"(view:"/index")
        "500"(view:'/error')
    }
}
于 2010-02-26T13:43:26.797 回答