0

I want to get data using a dynamic query or statement using iBATIS.

For example

select * from USERS where ID=1 or ID=12 or ID= 3 or ID=27.....

and I want to pass set of IDs as a List Object.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ishanaba
  • 65
  • 8

2 Answers2

1

You cam use IN statement

<select id="selectKeys" parameterType="list"
        resultMap="selectKeysResultMap">
        SELECT COL1,COL2
        FROM
        TABLE1
        WHERE COL1 IN
        <foreach item="item" index="index" collection="list" open="("
            separator="," close=")">
            #{item}
        </foreach>
    </select>
Karthik Prasad
  • 9,662
  • 10
  • 64
  • 112
1

In your DataConnector add this;

Map<String,Object> inputMap = new HashMap<String,Object>();

Map<String,Object> inputMap = new HashMap<String,Object>();

inputMap.put("idList", idList);

mapper.getMcqAnswers(inputMap);

In your DBMapper.xml add this;

<select id="getMcqAnswers" resultType="your result type">

select id,answers from mcqs where id in

<foreach item="item" index="index" collection="idList" open="(" separator="," close=")">

${item}

</foreach>

</select>
snil
  • 11
  • 3