MyBatis parameter from HashMap

2019-01-28 13:54发布

In mapper interface I have:

ArrayList<Item> select(@Param("filterId")int filterId, @Param("filterData")HashMap<String,Object> filterData);

In mapper xml I have:

 <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?

2条回答
太酷不给撩
2楼-- · 2019-01-28 14:06

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.

<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>
查看更多
放我归山
3楼-- · 2019-01-28 14:17

I found the answer:

 <select id="select" parameterType="map" resultMap="RM">
        SELECT ... 
        FROM ....
        WHERE id=#{filterData.id}
    </select>
查看更多
登录 后发表回答