0

在下面关于传递办公室代码列表的查询中,我得到了 countryID 的列表。现在,我需要一个 Map,其中的键是 countryID,它的值是办公室代码列表。你能帮我么。

示例:如果我们的办公室为abc,def属于国家123xyz属于789,我需要一个类似 (123, List(abc,def).... (789,List(xyz)))的地图

public List getData(List officeCode) {

    try {
        StringBuffer queryString = new StringBuffer("select distinct 
        (abc.countryID)  from com.#####.TABLE table");
        queryString.append(" where table.officeCode in (:oCode)");
        return SessionFactory.getCurrentSession()
        .createQuery(queryString.toString())
        .setParameterList("oCode",officeCode )
        .list();
    }
    catch (Exception e)

    {
        e.printStackTrace();
        return null;
    }

}
4

1 回答 1

0

执行以下查询:

select distinct abc.countryID, abc.officeCode from SomeEntity abc where abc.officeCode in (:codes)

此查询将返回一个List<Object[]>,每个对象数组包含一个 countryID 作为第一个元素,一个 office 代码作为第二个元素。

然后遍历列表,并填充您的地图。

注意:使用 StringBuffer 连接 String 文字会适得其反,而且可读性较差。你最好简单地做:

String queryString = "select distinct (abc.countryID)  from com.#####.TABLE table"
                     + " where table.officeCode in (:oCode)";
于 2012-11-30T16:32:07.927 回答