你能告诉我我的代码有什么问题吗?我想我已经正确地遵循了教程,但我的教程不起作用。我需要做的是列出来自 db 的数据。 这是我的代码。
Controller ..
class DailyProfitController {
def scaffold = DailyProfit
def index() {
render(view:"profitTable");
}
def save() {
// Date myDate = params.date('test', 'yyyy-MM-dd');
params.date_month = (Integer.parseInt(params.date_month)<10)? "0" + params.date_month : params.date_month;
params.date_day = (Integer.parseInt(params.date_day)<10)? "0" + params.date_day : params.date_day;
params.date = params.date_year + "-" + params.date_month + "-" + params.date_day
def dailyProfit = new DailyProfit(params)
println params.toString();
dailyProfit.save()
render(view:"profitTable");
}
def list(){
def dailyProfit = DailyProfit.list()
[dailyProfit:dailyProfit]
render(view:"profitTable");
}
}
HTML
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Profit</th>
<th>Delete?</th>
</tr>
</thead>
<tbody> <g:each in="${dailyProfit}" var="dailyProfit">
<tr>
<td><g:link action="show" id="${dailyProfit.date}">${dailyProfit.date}</g:link></td>
<td>${dailyProfit.profit}</td>
<td><button type="button" class="btn btn-default btn-lg">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
</button>
</td>
</tr> </g:each>
</tbody>
</table>
这是来自休眠的日志:
Hibernate: select this_.date as date0_0_, this_.profit as profit0_0_ from daily_profit this_
最佳答案
错误:
def list(){
def dailyProfit = DailyProfit.list()
[dailyProfit:dailyProfit]
render(view:"profitTable");
}
正确:
def list(){
def dailyProfit = DailyProfit.list()
render view:"profitTable", model: [dailyProfit : dailyProfit]
}
如果有效,请告诉我。
快乐编码。
关于mysql - chalice : not fetching/listing data from database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31917500/