2013-07-03 71 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