我有以下引导类
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时,我没有预先填充的类别或项目...任何想法为什么?
答案 0 :(得分:3)
您很可能有验证错误。
验证这一点的最快方法是向failOnError: true
添加.save()
,如下所示:.save(failOnError: true)
。
这应该会显示许多因验证错误而失败的事情。