0
为什么Grails的未填充数据我有以下的引导类通过引导
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'作为类别而不是类别对象,我创建了 –
与论坛网站不同,我们不使用“谢谢”或“任何帮助赞赏”或签名[so ]。请参阅“[应该'嗨','谢谢',标语和致敬从帖子中删除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be - 从帖子中删除)。顺便说一句,它是“提前致谢”,而不是“感谢先进”。 –