我正在尝试做一个购物车应用程序。我使用过 Spring 安全性。
我试图在我的 PurchaseOrder 域中实现一个方法,如下所示:
public void addToItems(Products products){
def purchaseItem = items?.find{it.products == products}
if (purchaseItem == null){
if (items == null){
items = []
}
items.add(new PurchaseItem(products:products,purchaseOrder:this,quantity:1,price:products.price))
}
else{
purchaseItem.quantity += 1
purchaseItem.price = products.price
}
}
这在 UserController.groovy
def addToCart = {
def products = Products.get(params.productsId)
if (products == null){
flash.error = "Could not add product to cart! Could find product with id [${params.productsId}]."
redirect(controller:'userInfo',action:'productSearch')
}
def purchaseOrderInstance = PurchaseOrder.findByUser(currentUser())
if (purchaseOrderInstance == null){
purchaseOrderInstance = new PurchaseOrder(user:currentUser())
}
purchaseOrderInstance.addToItems(products)
purchaseOrderInstance.save(flush:true)
redirect(action:'cart')
}
但我收到了这个错误:
Message: No signature of method: com.shop.PurchaseOrder.addToItems() is applicable for argument types: (null) values: [null]
Possible solutions: addToItems(java.lang.Object), addToItems(com.shop.Products), getItems()
Line | Method
->> 118 | doCall in com.shop.UserInfoController$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
我不确定我可能在哪里出错了,错误是什么意思?