我正在进行在线信用充值申请。 我想从数据库中按类别、类型和面额获取优惠券。 我需要有关在 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();
}
最佳答案
您需要这样的查询
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();
关于java - 多参数查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17451706/