【发布时间】:2021-02-12 12:08:15
【问题描述】:
我正在为我的应用程序使用 Spring Boot。使用 jdbctemplate 运行 MySQL 查询。
query = "Select * from users";
List<Map<String, Object>> response = jdbcTemplate.queryForList(query);
当前输出:
[
{
"id": 1,
"firstname": "Sam",
"address": "US"
},
{
"id": 2,
"firstname": "Alex",
"address": "US"
}
]
我想使用 jdbctemplate 返回如下输出。 jdbctemplate中是否有任何方法可以返回如下输出?
预期输出:
[
[
"id"
"firstname"
"address"
],
[
1,
"Sam",
"US"
],
[
2,
"Alex",
"US"
]
]
【问题讨论】:
-
试试这样的: List
-
您的
Current output是对网络请求的响应正文吗? -
@HopeyOne 是的,它是一个网络请求
-
@zatef jdbctemplate 中有没有现成的方法?
-
看起来不存在这样的方法..... jdbctemplate 的方法列表在这里,并且它们都不会返回数组数组(根据您的要求)。 docs.spring.io/spring-framework/docs/current/javadoc-api/org/…
标签: java spring-boot spring-jdbc jdbctemplate