Mybatis的foreach事列,如何获取foreach的index值

  1. XML文件里面:
  2. <select id="countByUserList" resultType="_int" parameterType="list">  
  3. select count(*) from users  
  4.   <where>  
  5.     id in  
  6.     <foreach item="item" collection="list" separator="," open="(" close=")" index="index">  
  7.       #{item.id, jdbcType=NUMERIC}  
  8.     </foreach>  
  9.   </where>  
  10. </select>  
  11. java里面就直接
  12. dao.find("userMapper.countByUserList", list);就可以了
  13. foreach中的index是遍历的当前索引,从0开始,相当于list集合里面的索引一样
  14. 取值的时候直接#{index}就可以了;
正在加载评论...