MyBatis parameter from HashMap

和自甴很熟 提交于 2019-11-28 09:00:00

问题


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?


回答1:


I found the answer:

 <select id="select" parameterType="map" resultMap="RM">
        SELECT ... 
        FROM ....
        WHERE id=#{filterData.id}
    </select>



回答2:


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>


来源:https://stackoverflow.com/questions/23829236/mybatis-parameter-from-hashmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!