gpt4 book ai didi

grails - 为什么grails不通过引导填充数据

转载 作者:行者123 更新时间:2023-12-02 15:00:28 24 4
gpt4 key购买 nike

我有以下 bootstrap 类

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)

那应该向您显示很多由于验证错误而失败的事情。

关于grails - 为什么grails不通过引导填充数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27879875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com