gpt4 book ai didi

java - 类似于 HQL 中的 % 运算符

转载 作者:行者123 更新时间:2023-11-30 02:21:39 24 4
gpt4 key购买 nike

我正在尝试运行下面的代码,但出现错误。

public MdFeedHandOff getFeedByHandOff(Integer handoff, Integer csiID){
logger.error("*************getFeedByHandOff(): handoff value is "+handoff);
String hql = "FROM MdFeedHandOff a WHERE a.handoff = :handoff and a.active in ('A','I') and to_char(a.handoff) like :csiID%";
Map<String, Object> param = new HashMap<String, Object>();
param.put("handoff", handoff);
List<MdFeedHandOff> batchJobList = searchForList(hql, param);
return batchJobList.isEmpty()?null:batchJobList.get(0);
}

我想在 hql 中使用像 % 运算符。请帮助我。我也尝试了下面的行,但它不起作用。

String hql = "FROM MdFeedHandOff a WHERE a.handoff = :handoff  and  a.active  in ('A','I') and to_char(a.handoff) like :csiID" + "%";

最佳答案

您应该将 :csid 参数名称放入查询中,并在您设置的参数中添加 % 通配符。另外,您似乎没有在参数映射中设置 csid。

查询:

FROM MdFeedHandOff a WHERE a.handoff = :handoff 
and a.active in ('A','I') and to_char(a.handoff) like :csiID";

参数:

Map<String, Object> param = new HashMap<String, Object>();
param.put("handoff", handoff);
param.put("csiID", csiId.toString()+"%");

关于java - 类似于 HQL 中的 % 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46666680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com