[英]MyBatis parameter from HashMap
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).没有错误,但结果不符合预期(它返回空集,但我知道存在具有此类 ID 的项目)。 The #{filterData["id"]} seems not to work.
#{filterData["id"]} 似乎不起作用。 Where is my mistake?
我的错误在哪里?
I found the answer:我找到了答案:
<select id="select" parameterType="map" resultMap="RM">
SELECT ...
FROM ....
WHERE id=#{filterData.id}
</select>
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
映射为查询的输入,并像这样作为不同的自定义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>
如果您的 id 是从列表中迭代的动态 ID,您可以使用 #{filterData.${id}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.