3

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?

4
  • And what is not expected? Commented May 23, 2014 at 12:27
  • @Konstantin V. Salikhov It returns empty set. Commented May 23, 2014 at 12:28
  • Why your attr is named sesultMap? Have you tried to debug? What parameter value is assigned to id at query time? Commented May 23, 2014 at 12:29
  • @Konstantin V. Salikhov sesultMap - I made mistake while was asking my question. Commented May 23, 2014 at 12:31

3 Answers 3

5

I found the answer:

 <select id="select" parameterType="map" resultMap="RM">
        SELECT ... 
        FROM ....
        WHERE id=#{filterData.id}
    </select>
Sign up to request clarification or add additional context in comments.

2 Comments

What is filterData? Is it a key of the map? And the filterData.id is the id attribute of the mapped value?
filterData is as specified in the annotation @Param("filterData") HashMap<String,Object> filterData, and id is one of its keys.
0

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>

Comments

0

If your id is dynamic which is iterated from a list you can use #{filterData.${id}}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.