圣杯。无法在名称为 'grailsDispatcherServlet' 的 servlet 中解析名称为 'index' 的视图

Grails. Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'

我开始使用 Grails (3.x) 框架,但在尝试将域内容呈现到视图时遇到此错误:

Error 500: Internal Server Error
URI /hello/index
Class javax.servlet.ServletException
Message: Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'

HelloController.groovy:

package helloworld   
class HelloController {

    def index() {
        def Person persona1 = new Person(firstName: "someone", lastName: "stuck", age: 21)
        [persona:persona1]
    }
}

Person.groovy:

package helloworld

class Person {
    String firstName
    String lastName
    int age
}

确保 grails-app/views/hello/index.gsp 文件存在。

我知道这有一个答案,但我想我会插话,因为我使用的是 Grails 3.0.11,我发现像下面这样的代码可以工作

render(view: 'index', model: [data: value])

其中以下内容将因上述错误而失败。

def index() {
    [data:value]
}

如果我有时间,我会多看看这个,并尝试了解发生了什么。

grails generate-views - 为给定域生成 GSP 视图 class

如果您正在使用 GNU/Linux,请检查文件夹名称、文件等是否大小写不一致。

grails-app/views/Hello/index.gsp
grails-app/views/hello/index.gsp <-- Not the same

GNU/Linux区分大小写。