gpt4 book ai didi

grails - 在Gson中渲染少量模型

转载 作者:行者123 更新时间:2023-12-02 15:19:15 25 4
gpt4 key购买 nike

是否可以将少量对象发送到gson渲染 View ?
我试图在 Controller 中使用:

respond trainings, [status: OK, view:"trainingsByClients", model: [myVariable: "test", anotherVariable: 123]]

并在 gson View 中:
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"
}
}
]
}

最佳答案

好的,我找到了解决方案:

    render(view: "trainingsByClients", model: [trainingList: trainings, myVariable: "asdg"])

所以我们应该使用 render而不是 respond。响应未正确添加其他模型对象。

关于grails - 在Gson中渲染少量模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41200464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com