mybatis 中in 怎么用 ?

本来是一个String字符串 “1001,1002,1003” 然后我用split分割逗号 得到了articleIDArray 数组
String[] articleIDArray = zt.getZtContentID().split(",");

public List<Article> getArticleZTbyArticleIDArray(String[] articleIDArray) {
return articleDao.getArticleZTbyArticleIDArray(articleIDArray);
}
我传递的是一个数组 articleIDArray 我参考着网上的写法写的 为什么有错误 
<select id="findArticleZTbyArticleIDArray" resultType="article" >
select articleID, articleTitle,date_format(createtime,'%Y-%m-%d %H:%i:%s') as createtime, tag from T_article
where flag='1' and articleID in 
<foreach item="articleIDArray" index="index" collection="array" 
open="(" separator="," close=")"> 
#{articleIDArray}
</foreach>
</select>
这是为什么 应该怎样改

呼啦一阵风
浏览 3142回答 2
2回答

RISEBY

1. 当查询的参数只有一个时findByIds(List<Long> ids)1.a 如果参数的类型是List, 则在使用时,collection属性要必须指定为 list<select id="findByIdsMap" resultMap="BaseResultMap">Select<include refid="Base_Column_List" />from jria where ID in<foreach item="item" index="index" collection="list"open="(" separator="," close=")">#{item}</foreach></select>findByIds(Long[] ids)1.b 如果参数的类型是Array,则在使用时,collection属性要必须指定为 array<select id="findByIdsMap" resultMap="BaseResultMap">select<include refid="Base_Column_List" />from jria where ID in<foreach item="item" index="index" collection="array"open="(" separator="," close=")">#{item}</foreach></select>2. 当查询的参数有多个时,例如 findByIds(String name, Long[] ids)这种情况需要特别注意,在传参数时,一定要改用Map方式, 这样在collection属性可以指定名称下面是一个示例Map<String, Object> params = new HashMap<String, Object>(2);params.put("name", name);params.put("ids", ids);mapper.findByIdsMap(params);<select id="findByIdsMap" resultMap="BaseResultMap">select<include refid="Base_Column_List" />from jria where ID in<foreach item="item" index="index" collection="ids"open="(" separator="," close=")">#{item}</foreach></select>完整的示例如下:例如有一个查询功能,Mapper接口文件定义如下方法:List<Jria> findByIds(Long... ids);使用 in 查询的sql拼装方法如下:<select id="findbyIds" resultMap="BaseResultMap">select<include refid="Base_Column_List" />from jria where ID in<foreach item="item" index="index" collection="array"open="(" separator="," close=")">#{item}</foreach></select>

拉莫斯之舞

我的也是字符拆成的数组,你这样:*Controller类中部分代码>>>String[] section = names.getModule().split(",");System.out.println("查询条件参数:"+list);List<EMS_TroubleShootingData> tsList = tsdService.getDataBySections(list);req.setAttribute("list", tsList);return "TroubleShootingList";Dao,Service及其实现类中都使用:(List<String> list);作为参数最后*Mapper.xml文件中:
打开App,查看更多内容
随时随地看视频慕课网APP