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

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参数名称,然后在您设置的参数中添加%通配符即可。另外,您似乎未在params映射中设置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/

10-10 21:58