我们如何使用ormlite将列从表转换为arraylist?

时间:2012-07-11 17:01:16

标签: ormlite

我试图在android上使用ormlite将整个列值转换为arrayList,这是可能的,直接api? 使用原始结果我接近但不完全:

GenericRawResults<String[]> rawResults =
     getHelper().getMyProcessDao().queryRaw(
         queryBuild.selectColumns("nid").prepareStatementString());
List<String[]> result = rawResults.getResults();

1 个答案:

答案 0 :(得分:3)

槽糕。我不确定这是你想要的。但是,通过使用可以传递给RawRowMapper DAO方法ORMLite'sdao.queryRaw(String, Rowmapper, String...)来实现您特别要求的一种方法。

以下内容应该有效:

RawRowMapper<Integer> mapper = new RawRowMapper<Integer>() {
     public Integer mapRow(String[] columnNames, String[] resultColumns) {
        // maybe you should verify that there _is_ only 1 column here
        // maybe you should handle the possibility of a bad number and throw
        return Integer.parseInt(resultColumns[0]);
     }
};
GenericRawResults<Integer> rawResults =
    getHelper().getMyProcessDao().queryRaw(
        queryBuild.selectColumns("nid").prepareStatementString(), mapper);
List<Integer> list = rawResults.getResults();