我想使用iBATIS使用动态查询或语句来获取数据。
例如
select * from USERS where ID=1 or ID=12 or ID= 3 or ID=27.....
我希望将一组ID作为列表对象传递。
答案 0 :(得分:1)
你可以使用IN语句
<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>
答案 1 :(得分:1)
在您的DataConnector中添加此内容;
Map<String,Object> inputMap = new HashMap<String,Object>();
Map<String,Object> inputMap = new HashMap<String,Object>();
inputMap.put("idList", idList);
mapper.getMcqAnswers(inputMap);
在您的DBMapper.xml中添加此内容;
<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>