use*_*800 0 java spring-jdbc jdbctemplate spring-data-jpa
我有这个作为我的查询。
select a.cust_id,a.cust_name,b.cust_id,b.cust_name
from acustomer a,bcustomer b
Run Code Online (Sandbox Code Playgroud)
DaoImp 使用 Spring NamedJdbcparameterTemplate
方法:
NamedJdbcparameterTemplate temp= new NJPT(datasource);
List<Map<String,Object>> out=temp.quertForList(query,parametermap);
Run Code Online (Sandbox Code Playgroud)
但问题是,每当我得到这个查询在数据库工具的输出,我得到4列,但在程序的输出,我只得到2列,即cust_id和cust_name的是越来越被覆盖b,由于在地图相同的键名。
我该如何解决这个问题,请注意每次查询都会有所不同,因为我将此方法用作程序的通用方法,并且输出将是值列表,因此无法为输出映射任何模型类。
请注意,我希望这个函数是通用函数,这意味着每次查询都会发生变化,并且输出将是不同类型的。
那么简单的解决方案是给你的字段别名,这样它们的键就会不同。
select a.cust_id a_cust_id, a.cust_name a_cust_name, b.cust_id b_cust_id, b.cust_name b_cust_name
from acustomer a, bcustomer b
where a.cust_id=b.cust_id
Run Code Online (Sandbox Code Playgroud)
然后在地图中您会找到别名、a_cust_id、a_cust_name、b_cust_id、b_cust_name。