1

我使用以下代码创建了一个新的 grails 应用程序

grails create-app myapp --profile=rest-api

我修改了ApplicationController并为其添加了命名空间,如下所示:

class ApplicationController implements PluginManagerAware {

     /** The Namespace for the version of the API, see http://docs.grails.org/latest/guide/REST.html#versioningResources */
     static namespace = "v1"

     GrailsApplication grailsApplication
     GrailsPluginManager pluginManager

     def index() {
         [grailsApplication: grailsApplication, pluginManager: pluginManager]
     } 
}

目录下有一个index.gson文件views/application/

我使用运行此设置grails run-app并将我的浏览器指向http://localhost:8080

它抛出以下异常:

<=======2020-04-08 16:01:31.616 ERROR --- [nio-8080-exec-1] .a.c.c.C.[.[.[.[grailsDispatcherServlet] : Servlet.service() for servlet [grailsDispatcherServlet] in context with path [] threw exception [Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'] with root cause

但是,如果我修改控制器代码使用render,一切正常。

render(view:'index',model: [grailsApplication: grailsApplication, pluginManager: pluginManager])

grails -v 的输出 Grails 版本:4.0.2
JVM 版本:1.8.0_171 操作系统:macOS High Sierra

4

1 回答 1

0

请参阅为命名空间控制器选择视图

命名空间视图的正确路径应该是:

grails-app/views/v1/application/index.gson
于 2020-04-08T13:47:16.647 回答