chaosxin 发表于 2016-11-27 10:30:58

Mybatis 中 in 语法 的# 与 $区别

今天写map时,(伪代码):update xxx t set t.a='1' where id in (#{ids});
当ids传入为string 1,2,3 时,得出效果只是更新了id=1的数据,原来#{xxx}是一个字符串,mybatis只会当他是一个值,如果你想达到字面上的效果:
1 用${ids} 把ids当成字符串传进来
2 update xxx t set t.a='1' where id in
<foreach collection="ids" index="index" item="id" open="(" close=")" separator=",">
   #{id}
</foreach>
注意要把 ids对象成数组才生效

。。有点乱,不过只是又遇到就记录下
页: [1]
查看完整版本: Mybatis 中 in 语法 的# 与 $区别