【问题标题】:Query by more than one parameters多参数查询
【发布时间】:2013-07-01 08:41:48
【问题描述】:

我正在做一个在线信用充值申请。 我想按类别、类型和面额从数据库中获取凭证。 我需要有关在 creatquery() 和 setparameter() 方法中插入的查询的帮助。 这是我获取优惠券的代码 sn-p。

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();
    }

【问题讨论】:

  • 我猜凭证不是字符串
  • @AlmoullimDev。 php?这是java xD
  • @nachokk 哦!!那我一定是疯了sorry:L

标签: java mysql hibernate jakarta-ee


【解决方案1】:

你需要这样的查询

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();

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 1970-01-01
    • 2022-01-18
    • 2020-10-16
    • 1970-01-01
    • 2014-08-22
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多