Java 春季地图回归图
我使用Spring的Java 春季地图回归图,java,spring,Java,Spring,我使用Spring的jdbcTemplate检索多个查询。我目前正在使用queryForList方法。但我想将所有这些查询合并到一个映射中,输出如下: { customers : { firstname : "John", lastname: "Doe", phone : "1-888-888-8888" gender: "M" }, data: { key1 : "value1"
jdbcTemplate
检索多个查询。我目前正在使用queryForList
方法。但我想将所有这些查询合并到一个映射中,输出如下:
{
customers : {
firstname : "John",
lastname: "Doe",
phone : "1-888-888-8888"
gender: "M"
},
data: {
key1 : "value1",
key2 : "value2",
key3 : "value3"
},
etc....
}
如果我将客户
下的所有内容作为一个查询:
return jdbcTemplate.queryForList(customersql, param);
将数据下的所有内容作为不同的查询:
return jdbcTemplate.queryForList(datasql, param);
如何使用Spring从这两个查询中获得预期的输出?我的理解是,
queryForMap
只返回一行,所以这是不可能的。任何帮助都将不胜感激。几乎可以肯定有一个更优雅的解决方案,但乍一看,一个选择似乎是自己构建这样一个地图:
Map<String, ...> map = new HashMap<>();
map.put("customers", jdbcTemplate.queryForList(customersql, param));
map.put("data", jdbcTemplate.queryForList(datasql, param));
return map;
Map Map=newhashmap();
map.put(“customers”,jdbcTemplate.queryForList(customersql,param));
map.put(“data”,jdbcTemplate.queryForList(datasql,param));
返回图;