mysql - chalice : not fetching/listing data from database

标签 mysql grails select

你能告诉我我的代码有什么问题吗?我想我已经正确地遵循了教程,但我的教程不起作用。我需要做的是列出来自 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/

相关文章:

grails - 即使成功注销后,按浏览器后退按钮仍可重新登录

r - 如果组内出现特定数字,则将数据框中的行标记为 "TRUE"

php - 为什么这是 PHP 中的错误 MYSQL 查询?

jquery - 使用 JQuery 处理动态字段时 Grails 表单提交失败

Mysql触发数学计算

Grails,比较两个对象?

MySQL select where in but not in with join

我能否保证在 select() 报告套接字已准备好读取后 recv() 不会阻塞?

php - mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows等…期望参数1为资源或结果

mysql - 本月和上个月两个日期时间之间的平均时间