Grails没有找到控制器的视图

时间:2014-12-23 14:07:05

标签: grails model-view-controller gsp

我有以下Grails 2.3.6 app结构(除了普通/默认的Grails结构):

myapp/
    grails-app/
        controllers/
            fizzbuzz/
                SomeUserController.groovy
        views/
            someUser/
                someUser.gsp

SomeController

class SomeController {
    def index() {
        // Do a bunch of stuff

        render(
            view: "someUser",
            model: [
                someModel: someModel,
                anotherModel: anotherModel
            ]
        )
    }
}

当我运行grails run-app并打开浏览器

http://localhost:8080/myapp/fizzbuzz/someUser

Grails提供我自定义的404 Not Found页面。 发生了什么,我该怎么做才能解决问题?

1 个答案:

答案 0 :(得分:3)

问题中描述的内容存在一些问题。

您有grails-app/controllers/fizzbuzz/SomeUserController.groovy的控制器,然后显示SomeController的代码。类名和文件名应该相互匹配。您应该将SomeUserController.groovy重命名为SomeController.groovy,或将该类从SomeController重命名为SomeUserController。请注意,存储视图的目录需要与之保持同步。如果控制器为SomeController,则视图将进入grails-app/views/some/。如果控制器为SomeUserController,则视图将进入grails-app/views/someUser/

您显示的网址是http://localhost:8080/myapp/fizzbuzz/someUser。除非你在UrlMappings.groovy中有一些特殊的映射来支持它,否则这将不起作用。如果控制器为http://localhost:8080/myapp/someUser,则可能需要SomeUserController,如果控制器为http://localhost:8080/myapp/some,则可能需要SomeController