java 从 IBatis 获取 Map<String,CustomData>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14348887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fetch Map<String,CustomData> from IBatis
提问by Echo
I am creating an ibatis quesry that its result should be :
我正在创建一个 ibatis 查询,其结果应该是:
Map<String,CustomData>
My ibatis query:
我的 ibatis 查询:
<resultMap id="dataMap" class="java.util.HashMap">
<result property="key" column="UUID"/>
<result property="value" resultMap ="customData"/>
</resultMap>
<resultMap id="customData" class="com.model.CustomData">
<result property="x" column="X_COL"/>
</resultMap>
<select id="fetchData"
resultClass="java.util.HashMap"
parameterClass="java.util.Map">
SELECT
UUID AS UUID,
(CASE
WHEN SOME_DATA IS NOT NULL THEN 'TRUE'
END) AS X_COL
FROM TABLE
</select>
CustomData is a java class:
CustomData 是一个 Java 类:
public class CustomData{
private String x;
//Getters & Setters
}
I expect to get the following on the Java:
我希望在 Java 上获得以下内容:
Map<String,CustomData>
However I get the following:
但是我得到以下信息:
Map<String,String>
Any ideas !
有任何想法吗 !
回答by zoom
You should try to replace the resultClass
attribute in your select
tag by a resultMap
with a "dataMap"
value like this :
您应该尝试将标记中的resultClass
属性替换select
为resultMap
具有如下"dataMap"
值的a :
<select id="fetchData"
resultMap="dataMap"
parameterClass="java.util.Map">
<!-- your query -->
</select>
In your case the queryForList
method try to instanciate a java.util.HashMap
instead of this, it should use the dataMap
mapping you defined above.
在您的情况下,该queryForList
方法尝试实例化 ajava.util.HashMap
而不是 this,它应该使用dataMap
您在上面定义的映射。