【发布时间】:2026-02-02 04:00:01
【问题描述】:
是否可以将少量对象发送到 gson 渲染视图? 我尝试在controller中使用:
respond trainings, [status: OK, view:"trainingsByClients", model: [myVariable: "test", anotherVariable: 123]]
在 gson 视图中:
model {
Iterable<Training> trainingList
String myVariable
}
json {
myVariable myVariable
trainings tmpl.training(trainingList ?: [])
}
它会回复:
{
"myVariable": null,
"trainings": [
{
"id": 3,
"name": "test t",
"numberOfAbsentClients": 0,
"startDate": "2016-11-20T09:00:00+0000",
"numberOfClients": 2,
"section": {
"id": 1,
"name": "test sec"
}
},
{
"id": 10,
"name": "test 2",
"numberOfAbsentClients": 0,
"startDate": "2016-11-09T11:00:00+0000",
"numberOfClients": 2,
"section": {
"id": 2,
"name": "sec 2"
}
}
]
}
【问题讨论】: