2013-11-26 46 views
0

我想使用動態查詢或語句使用iBATIS來獲取數據。如何在iBATIS中使用「或」語句編寫查詢?

例如

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

,我想通過設置ID作爲一個列表對象的。

+0

你可以這樣做嗎?select * from USERS where ID IN('1','12','3','27',...) –

回答

1

你凸輪使用報表

<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

在你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> 
相關問題