Pan*_*don 5 rest grails json gsp
我希望我的 Grails 3.1.5 应用程序使用 *.gson 格式提供 JSON 数据,并且对于某些页面/URL,我想继续使用 GSP。
我使用 rest-api 配置文件构建了一个应用程序。然后我从我使用 web-api 构建的其他应用程序中复制了控制器和视图。
在这样做时,为了保持一致,我还将 index.gson 移到了不同的位置。
现在我得到一个:
Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'
Run Code Online (Sandbox Code Playgroud)
开始深入研究 3.1.5 代码库中可用的 viewResolvers。rest-api 配置文件可能会配置一个 viewResolver 以在某个位置查找 *.gson 文件。
无论如何,是否可以配置一个 CompositeViewResolver 来查找视图 *.gson 和 *.gsps?
如果是这样,我该怎么做?
谢谢!
小智 5
我已经通过将这个插件添加到 build.gradle 来解决这个问题:
compile 'org.grails:grails-plugin-gsp'
Run Code Online (Sandbox Code Playgroud)
并与两者
profile 'org.grails.profiles:web'
profile 'org.grails.profiles:rest-api'
Run Code Online (Sandbox Code Playgroud)
并应用插件
apply plugin: 'org.grails.grails-web'
apply plugin: 'org.grails.grails-gsp'
apply plugin: 'org.grails.plugins.views-json'
Run Code Online (Sandbox Code Playgroud)
显然,他们在您使用 REST 配置文件时将其删除,以减少开销,因为您很少在 REST 服务端呈现 HTML。