`

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,2,3]才生效

。。有点乱,不过只是又遇到就记录下
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics