首页 > 代码库 > HIbernate 查询拼接参数

HIbernate 查询拼接参数

public List<TrailTestModel> findByEid(List<String> trailids, String eid) {
// TODO Auto-generated method stub
String hql = " from TrailTestModel where 1=1 ";
ArrayList<String> count = new ArrayList<String>();
if (trailids != null && trailids.size() > 0) {
hql += " and trail.uid in (:trailids) ";
}
if (StringUtils.isNotBlank(eid)) {
hql += " and employee.uid = :eid ";
count.add(eid);
}
Query query = hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(hql);
Object[] arr = new Object[trailids.size()];
for (int i = 0; i < trailids.size(); i++) {
arr[i] = trailids.get(i);
}
if (trailids != null && trailids.size() > 0) {
query.setParameterList("trailids", arr);
}
if (StringUtils.isNotBlank(eid)) {
query.setParameter("eid", eid);
}
List<TrailTestModel> list = query.list();
return list;
}

HIbernate 查询拼接参数