【问题标题】:why is grails not populating data via bootstrap为什么 grails 不通过引导程序填充数据
【发布时间】:2015-01-10 18:44:52
【问题描述】:

我有以下引导类

import shoppingsolutionproject.Category;
import shoppingsolutionproject.Item

class BootStrap {

    def dataSource

    def init = { servletContext ->
        new Category(description: 'Car').save()
        new Category(description: 'Truck').save()
        new Item(productNumber:1, name:"First Product", description: "This is the first product I'm adding for testing",
                 shippingCost: 4.99, url: '/first', retailPrice: 19.99, salePrice: 16.99, category: 'Car').save()
        new Item(productNumber:2, name:"Second Product", description: "This is the second product I'm adding for testing",
                shippingCost: 4.99, url: '/second', retailPrice: 19.99, category: 'Truck').save()
        new Item(productNumber:3, name:"First/Second Product", description: "This is the first/second(so third) product I'm adding for testing",
                shippingCost: 4.99, url: '/second', retailPrice: 17.99, category: 'Truck').save()
    }
    def destroy = {
    }
}

但是,当我启动 grails 时,我没有预先填充类别或项目...知道为什么吗?

【问题讨论】:

  • 您很可能有验证错误。验证这一点的最快方法是将failOnError: true 添加到您的.save(),如下所示:.save(failOnError: true)。这应该会显示很多由于验证错误而失败的事情。
  • @JoshuaMoore 你是对的,我使用字符串'Car'作为类别而不是我创建的类别对象
  • 与论坛网站不同,我们不使用“谢谢”、“任何帮助表示赞赏”或Stack Overflow 上的签名。请参阅“Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?。顺便说一句,这是“提前致谢”,而不是“致谢”。

标签: grails grails-orm bootstrapping


【解决方案1】:

您很可能有验证错误。

验证这一点的最快方法是将failOnError: true 添加到您的.save(),如下所示:.save(failOnError: true)

这应该向您展示许多由于验证错误而失败的事情。

【讨论】:

    猜你喜欢
    • 2014-11-05
    • 2013-07-25
    • 1970-01-01
    • 2014-11-17
    • 2016-01-09
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多