0
StringBuilder query = new StringBuilder("from country ");
query.append("and stateId in (:stateId)");
hqlNamedParam.addParamAndValue("stateId", values);

如果表中不存在“值”,则获取所有行。

我该怎么做?

4

1 回答 1

0

我误解了这个问题,现在我编辑我的答案:

您必须运行两个查询。

// The first:

StringBuilder query = new StringBuilder("from country ");
query.append("and stateId in (:stateId)");
hqlNamedParam.addParamAndValue("stateId", values);

// The second (only if the first doesn't return rows)

if (outList == null || outList.size == 0) {
    StringBuilder query2 = new StringBuilder("from country ");
}

或者(但您使用更多带有计数的子查询)

StringBuilder query = new StringBuilder("from country ");
query.append(" where 
    (select count(c2.id) from country c2 where c2.stateid in (:stateId)) > 0
    and cs.stateid in (:stateId)
    or (select count(c3.id) from country c3 where c3.stateid in (:stateId)) = 0");
hqlNamedParam.addParamAndValue("stateId", values);
于 2013-08-27T10:16:35.083 回答