[英]Grails not displaying SQL results in table, what am I missing?
我显然在这里缺少明显的东西,但是我一生都无法解决,我设置了一个视图来显示自定义SQL查询,但是屏幕什么也没显示,这就是我所拥有的
控制者
def queueBreakdown(){
String SQLQuery = "select state, count(test_exec_queue_id) as 'myCount' from dbo.test_exec_queue group by state"
def dataSource
def list = {
def db = new Sql(dataSource)
def results = db.rows(SQLQuery)
[results:results]
}
}
如果我手动运行此命令,则会像这样返回一组结果
state myCount
1 1
test 2
test2 1
queueBreakdown.gsp具有以下内容...
<body>
<a href="#list-testExecQueue" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content…"/></a>
<div class="nav" role="navigation">
<ul>
<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
</ul>
</div>
<div id="queueBreakdown-testExecQueue" class="content scaffold-list" role="main">
<h1><g:message code="Execution Queue Breakdown" /></h1>
<table>
<thead>
<tr>
<g:sortableColumn property="Run State" title="Run State"/>
<g:sortableColumn property="Count" title="Count" />
</tr>
</thead>
<tbody>
<g:each in="${results}" status="i" var="it">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td>${it.state}</td>
<td>${it.myCount}</td>
</tr>
</g:each>
</tbody>
</table>
</div>
</body>
但是,当我查看该页面时,我什么也没得到...表格已经建立,但是其中没有任何行,我在这里感到什么粗心?
干杯
您的控制器代码确实令人困惑,这里的动作是什么? queueBreakdown()或list()? 似乎您将2个动作混在一起了,并且queueBreakdown()没有返回任何模型...
class SomeController {
def dataSource
def queueBreakdown() {
String SQLQuery = "select state, count(test_exec_queue_id) as 'myCount' from dbo.test_exec_queue group by state"
def db = new Sql(dataSource)
def results = db.rows(SQLQuery)
[results:results]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.