在我的域类中 com.example.users.User 我添加了临时现场证:
class User implements Serializable {
...
def carnets
static transients = ['springSecurityService', 'carnets']
...
}
在我的 gson View 中 用户/_user.gson 我想渲染它:
import com.example.users.User
model {
User user
}
json g.render(user, [excludes:['password', 'deleted', 'enabled', 'accountExpired', 'accountLocked', 'passwordExpired', 'authorities']]) {
//"carnets" g.render(template:"/carnet/index", collection: user.carnets, var:'carnets')
"carnets" tmpl.'/carnet/index'(user.carnets)
}
但我收到了:
Caused by: grails.views.ViewRenderException: Error rendering view: Template not found for name /carnet/index
Carnet 的 View gson 文件是自动生成的,从 CarnetController 执行时可以正常工作。
我错过了什么?
最佳答案
在我的用例(Grails 3.3.0)中,我不得不将模板路径从:tmpl.'message/message'
到:tmpl.'/message/message'
(添加前导斜线)。
使用 ../
语法在开发中有效,但在将 WAR 文件部署到 Tomcat 时对我造成了错误。见:[ https://github.com/grails/grails-views/issues/140]
关于找不到名称的 Grails 3.2.0.M1 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40439411/