MyBatis Issue with IN Condition <foreach with List inside a Map

后端 未结 2 1617
孤独总比滥情好
孤独总比滥情好 2021-01-16 08:48

I have to build a IN condition using MyBatis where have to pass a list of PARENT_VALUES to be obtained based on the foreach loop below....

I tried but u

相关标签:
2条回答
  • 2021-01-16 09:01

    Your Select statement would like something like this

    <select id="getNameAgeDetails" parameterType="map" resultMap="someResultMap">
            SELECT P.NAME, P.AGE
            FROM PERSON_DETAILS P
            WHERE
             SOMECOLUMN is NULL
            AND DATA IN
              (SELECT DATA
              FROM PARENT_TABLE
              WHERE PARENT_VALUE IN 
             <FOREACH item="item"  index="index" collection="list" separator="," open="(" close=")"> 
                    ${item}
                </FOREACH>  
              )
              ORDER BY P.NAME
              FETCH 
                FIRST 10 ROW ONLY 
      </select>
    
    0 讨论(0)
  • 2021-01-16 09:21

    I agree with Karthik Prasad and if you remove CDATA and have sth like

    a_column>=6 AND b_column<10
    

    you must do the XML escape just as below:

    a_column &gt;= 6 AND b_column &lt; 10
    
    0 讨论(0)
提交回复
热议问题