找不到名称的Grails 3.2.0.M1模板

找不到名称的Grails 3.2.0.M1模板,grails,gson,grails3,Grails,Gson,Grails3,在我的域类com.example.users.User中,我添加了瞬态字段卡片: class User implements Serializable { ... def carnets static transients = ['springSecurityService', 'carnets'] ... } 在我的gson视图中,user/\u user.gson我想呈现它: import com.example.users.User model {

在我的域类com.example.users.User中,我添加了瞬态字段卡片:

class User implements Serializable {
    ...
    def carnets

    static transients = ['springSecurityService', 'carnets']
    ...
}
在我的gson视图中,user/\u 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)
}
但我收到了:

原因:grails.views.ViewRenderException:错误呈现视图:找不到name/carnet/index的模板

Carnet的视图gson文件是自动生成的,从CarnetController执行时工作正常


我缺少什么?

不幸的是,您需要使用当前
.gson
文件中模板的相对路径。我可以想象,该选项是来自
视图
文件夹的相对路径,但显然不是这样

假设您的
视图
文件夹结构如下:

views/
    carnet/
         _index.gson
    user/
        _user.gson
import com.example.users.User

model {
    User user
}

json g.render(user, [excludes:['password', 'deleted', 'enabled', 'accountExpired', 'accountLocked', 'passwordExpired', 'authorities']]) {
    "carnets" tmpl.'../carnet/index'(user.carnets)
}
在这种情况下,您的
\u user.gson
文件需要如下所示:

views/
    carnet/
         _index.gson
    user/
        _user.gson
import com.example.users.User

model {
    User user
}

json g.render(user, [excludes:['password', 'deleted', 'enabled', 'accountExpired', 'accountLocked', 'passwordExpired', 'authorities']]) {
    "carnets" tmpl.'../carnet/index'(user.carnets)
}
TL;DR将
tmpl./carnet/index'
更改为
tmpl.../carnet/index'
:)

在我的用例(Grails 3.3.0)中,我必须从以下位置更改模板路径:
tmpl.“消息/消息”
致:
tmpl./message/message'
(添加了前导斜杠)


使用
。/
语法在开发中起作用,但在将WAR文件部署到Tomcat时给我造成了一个错误。请参阅:[

第一步显然应该升级到比您正在使用的主版本的第一个里程碑版本更新的版本,在本例中,我尝试了3.2.2版本:但感谢您的提示。