一次渲染多个对象
我正在尝试将多个对象呈现为 JSON。我的控制器代码如下所示:
def showClient = {
if (springSecurityService.isLoggedIn()) {
def q_param = params.name_startsWith;
def listOfClients =ClientRole.findAll("FROM ClientRole WHERE party.name LIKE ? AND is_active =true",["%"+q_param+"%"])
def point= Point.get(1)
ArrayList<DisplayableName> clientList = ParameterFormatter.getFormattedDisplayNameList(listOfClients)
def json = clientList as JSON
log.debug("showClients :: jsondata = "+json)
render json
}else{
redirect(controller:'login',action: "auth")
}
}
这里我仅将 clientList
渲染为 json,但我还想渲染 point
对象。如何同时渲染 clientList
和 point
对象?
I am trying to render multiple objects as JSON. My controller code looks like:
def showClient = {
if (springSecurityService.isLoggedIn()) {
def q_param = params.name_startsWith;
def listOfClients =ClientRole.findAll("FROM ClientRole WHERE party.name LIKE ? AND is_active =true",["%"+q_param+"%"])
def point= Point.get(1)
ArrayList<DisplayableName> clientList = ParameterFormatter.getFormattedDisplayNameList(listOfClients)
def json = clientList as JSON
log.debug("showClients :: jsondata = "+json)
render json
}else{
redirect(controller:'login',action: "auth")
}
}
Here I am rendering only clientList
as json, but I also want to render the point
object. How can I render both clientList
and point
object at the same time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试:
这将产生一个 JSON 对象,如下所示:
You can try:
This will result in a JSON object like:
在渲染为 JSON 之前,我总是将所有内容放入地图中!所以试试这个:
I always put everything in a map before rendering as JSON! so try this: