簡體   English   中英

我嘗試使用grails和groovy根據條件從PostgreySQL獲取數據,但是在訪問列表foregin鍵id時遇到了問題

[英]I try to get data from postgreySQL basis on criteria using grails and groovy but i am facing issue while accesing the list foregin key id

ProductViewerController.groovy

 class ProductViewerController {

    def index(Integer id) { 
  def result=ProductLoader.createCriteria().list {
   eq("product_barcode",id)
  }

  result.each {
   notes->println "${notes}"
  }
  render(view:'index.gsp')  
 }
}

ProductLoader.groovy(模型類)

  class ProductLoader { String store double price String notes static belongsTo =[product_barcode : Product] static constraints = { store() price() notes() } } 

我試圖根據外鍵ID獲取數據,然后獲取classCastException: 在此處輸入圖片說明

需要將屬性product_barcodeProduct的對象類型進行比較

def result = ProductLoader.createCriteria().list {
   eq("product_barcode", Product.get(id))
}

或者你像這樣加入外國餐桌

def result = ProductLoader.createCriteria().list {
   product_barcode {
       eq("id", id)
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM