【发布时间】:2011-11-30 06:15:51
【问题描述】:
我将值保存在两个表资产和资产历史中。在创建资产时,如果有任何更新,我将在资产表中保存值,以便将其存储在资产和资产历史中以 id 为基础。现在我想在编辑页面中获取两个表值以获取asset_history 我使用sql查询来获取asset_history中的值。所有工作都很好,但它出现在数组列表值中(所有更新列表都显示在单行中)。当我更新了编辑页面中的值,它应该保存并显示在asset_history的不同行中。为此,我使用了 for 循环,但它没有获取值。
资产表我有这些字段:-
id
asset_title
asset_description
client_id
comment
status
etc...
在asset_history 字段中:-
id
comment
update_on
update_by
status
如果资产字段有任何更新。更新列表应该保存在资产和资产历史中。我使用查询来更新(如下所示)。但它正在asset_history表中获取arraylist。
编辑操作
def dataSource
def edit={
def assetInstance = Asset.get(params.id)
if (!assetInstance) {
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'asset.label', default: 'Asset'), params.id])}"
redirect(action: "list")
}
else { Sql sql = new Sql(dataSource)
def result = sql.rows("SELECT * from asset_history where id ='"+params.id+"' ")
//def n=result
/* def arr = (String[])result
for(i in 0 .. result.size()-1)
{
return [assetInstance: assetInstance,result:i]
}*/
return [assetInstance: assetInstance,result: result]
}
}
在edit.gsp中
<tbody>
<tr>
<td>${result.id}</br></td>
<td>${result.comment}</br></td>
<td>${result.update_on}</br></td>
<td>${result.update_time}</br></td>
<td>${result.update_by}</br></td>
</tr>
</tbody>
在asset_history表中,值在arraylist中并在单行中显示更新列表。但我想在单独的行中显示它,当我每次更新时。我为此使用了for循环,但它不起作用。请指导我来解决这个问题。
【问题讨论】:
-
为了得到更好的答案,您可能对这个帖子感兴趣:meta.stackexchange.com/a/81648。尝试写较短的问题,并努力写出好的英语。
标签: grails groovy grails-controller