Java Spring JDBC查询添加到映射

Java Spring JDBC查询添加到映射,java,spring,spring-mvc,jdbc,Java,Spring,Spring Mvc,Jdbc,我使用SpringJDBC框架从数据库中获取两列。我已经使用“映射器”实现了“RowMapper”类,并执行如下查询: List<Entity> rows = template.query(sql, new EntityMapper()); 如何在spring中将查询行存储到映射中,并将ID设置为键,值为account queryForList返回LinkedHashMap对象的列表 为了得到Map,我们需要像下面这样转换queryForList方法的结果 List

我使用SpringJDBC框架从数据库中获取两列。我已经使用“映射器”实现了“RowMapper”类,并执行如下查询:

List<Entity> rows = template.query(sql, new EntityMapper());
如何在spring中将查询行存储到映射中,并将ID设置为键,值为account

queryForList返回LinkedHashMap对象的列表

为了得到Map,我们需要像下面这样转换queryForList方法的结果

       List list = template.queryForList(...);
        for (Object o : list) {
           Map m = (Map) o;
           <your code here which uses Map objects>
        }

有关该方法的更多信息

请尝试queryForList,它将返回一个Map对象
 public List<String> getID() {
    if (accountsByID.isEmpty()) {
        return Collections.EMPTY_LIST;
    } else {
        return new ArrayList<String>(accountsByID.keySet());
    }
}
       List list = template.queryForList(...);
        for (Object o : list) {
           Map m = (Map) o;
           <your code here which uses Map objects>
        }