重新调整gson中的几个模型 [英] Redering few models in gson

查看:118
本文介绍了重新调整gson中的几个模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能向gson渲染视图发送少量对象?
我尝试在控制器中使用:

 回复训练,[status: view:trainingsByClients,model:[myVariable:test,anotherVariable:123]] 

和在 gson视图中:

 模型{
Iterable< Training> trainingList
String myVariable
}

json {
myVariable myVariable
trainings tmpl.training(trainingList?:[])
}

,并回应:

  {
myVariable:null,
trainings:[
{
id:3,
name:测试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
}
} $ [b $ b]
}


解决方案

我找到了解决方案:

  render(view:trai ningsByClients,model:[trainingList:trainings,myVariable:asdg])

渲染而不是响应。回应没有正确添加其他模型对象。

Is it possible to send few objects into gson rendering view? I tried to use in controller:

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

and in gson view:

model {
    Iterable<Training> trainingList
    String myVariable
}

json {
    myVariable myVariable
    trainings tmpl.training(trainingList ?: [])
}

and it responds with:

{
  "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"
      }
    }
  ]
}

解决方案

ok, I found solution:

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

so we should use render instead of respond. Respond is not adding properly additional model objects.

这篇关于重新调整gson中的几个模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆