2016-08-03 43 views
0

我寫了一個查詢幫助: -的MyBatis/ibatis的: - 關於ibatis的/ MyBatis的查詢

<select id="fetchEndPointArn" parameterType="map" resultType="com.rohit.service.model.UserActive"> 
    select userid,endpointarns from t_user_actives where sid=#{sid} 
    and (userid in 
    <foreach item="userid" index="index" collection="userid" open="(" separator="," close=")"> 
     #{userid} 
    </foreach> 
     ) 
</select> 

我DaoImpl: -

@Override 
public List<UserActive> fetchEndPointArn(Map<String,String> map) { 
    List<UserActive> userActive=sqlSession.selectList("fetchEndPointArn",map); 
    return userActive; 
} 

地圖,我傳遞包含: -

sid=10,userid=t10,t12 

我收到一個例外說: -

Error evaluating expression 'userid'. Return value (t10,t12) was not iterable 
+0

試圖爲'item'和'collection'使用不同的參數名稱。 – Blank

回答

1

將參數類型更改爲java.util.Map。將您的收藏定義爲collection="list" instead of collection="userid"。最後,讓用戶id的ArrayList像這樣

List userid = new ArrayList(); 
userid.add("t10"); 
userid.add("t12"); 
Map paramMap = new HashMap(); 
paramMap.put("sid",10); 
paramMap.put("userid",userid); 

,然後在XML

<select id="fetchEndPointArn" parameterType="java.util.Map" resultType="com.rohit.service.model.UserActive"> 
    select userid,endpointarns from t_user_actives where sid=#{sid} 
    and userid in 
    <foreach item="userid" collection="list" index="index" open="(" separator="," close=")"> 
     #{userid} 
    </foreach> 
</select>