Java语言Mybatis中in语法的使用

200 阅读1分钟

今天写map时,(伪代码):

update xxx t set t.a='1' where id in (#{ids})

当ids传入为string 1,2,3 时,得出效果只是更新了id=1的数据,原来#{xxx}是一个字符串,mybatis只会当他是一个值,如果你想达到字面上的效果: 

update xxx t set t.a='1' where id in 
<foreach collection="ids" index="index" item="id" open="(" close=")" separator=","> 
   #{id} 
</foreach> 

注意要把 ids对象成数组[1,2,3]才生效