我用 rest-profile 构建了一个 grails 4.0.10 应用程序。
然后添加了控制台插件。(因为太方便了)
compile 'org.grails.plugins:grails-console:2.1.1'
这依赖于gsps。
compile "org.grails.plugins:gsp" // console plugin needs to render gsps.
添加 gsp 插件后,404 处理程序现在呈现默认的 notFound.gsp 而不是 notFound.gson 文件。
有没有办法设置 URL 映射以默认呈现 .gson 视图而不是 .gsp 视图?
我发现的唯一机制是创建一个错误控制器来手动处理它,但我觉得我忽略了 UrlMappings 中非常简单的东西。
class UrlMappings {
static mappings = {
...
"404"(controller: "error", action:'notFound')
}
}
然后创建一个 errorController 来渲染视图。
class ErrorController {
static responseFormats = ['json', 'xml']
def notFound() {
render(view: "/notFound")
}
}
这里希望 "404"(view: '/notFound', pleaseUseGson: true)
设置我还没有找到。