2013-07-03 73 views
0

正在做一個在線信用充值申請。 我想從數據庫中獲取憑證的類別,類型和麪額。 我需要幫助查詢我插入creatquery()和setparameter()方法。 這是我的代碼片段獲取優惠券。通過多個參數查詢

public String getVoucherPinByCategoryTypeDeno(String category, String type, double denomination) { 
     return (String) sessionFactory.getCurrentSession().createQuery("from voucher v where v.category = :category and v.voucherType = :type and v.denomination = :denomination").setparameter().uniqueResult(); 
    } 
+0

我猜券不是一個字符串 – nachokk

+0

@AlmoullimDev。 PHP的?這是java xD – nachokk

+0

@nachokk哦!!,那麼我一定會失去我的想法'抱歉':L –

回答

2

您需要查詢像這樣

Voucher voucher = (Voucher) session.createQuery("from Voucher v where v.category = :category and v.voucherType = :type and v.denomination = :denomination") 
.setString("category", category) 
.setString("voucherType", type) 
.setDouble("denomination", denomination) 
.uniqueResult(); 
+0

謝謝這是有道理的 – Sanerty

+0

@Sanerty請接受答案:-) – nachokk