Java 来自 HashMap 的 MyBatis 参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23829236/
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
MyBatis parameter from HashMap
提问by
In mapper interface I have:
在映射器界面中,我有:
ArrayList<Item> select(@Param("filterId")int filterId, @Param("filterData")HashMap<String,Object> filterData);
In mapper xml I have:
在映射器 xml 中,我有:
<select id="select" parameterType="map" resultMap="RM">
SELECT ...
FROM ....
WHERE id=#{filterData["id"]}
</select>
No errors but the result is not as expected (it returns empty set but I know item with such id exists). The #{filterData["id"]} seems not to work. Where is my mistake?
没有错误,但结果不符合预期(它返回空集,但我知道存在具有此类 ID 的项目)。#{filterData["id"]} 似乎不起作用。我的错误在哪里?
采纳答案by
I found the answer:
我找到了答案:
<select id="select" parameterType="map" resultMap="RM">
SELECT ...
FROM ....
WHERE id=#{filterData.id}
</select>
回答by Rajesh
If you have pure java class you can map in the parameterType
as input to the query and return as different custom pojo class
like this.
如果您有纯 Java 类,您可以将parameterType
as 输入映射到查询并作为不同的自定义返回pojo class
。
<select id="getCustomMember" parameterType="com.custom.member" resultMap="custDocMap">
select
customer_id, cust_start_dt, cust_type, src_sys_doc_id,
legal_backer_id, eenv_create_dt
from
web_data..wd_edoc
where
eenv_create_dt = #{member.date}
</select>