ibatis中书写SQL语句时使用in遇到的问题

update user set flag=#flag# where id in (#id#)

传递的id为1,2,3。但是数据却没有任何的修改。

因为iBATIS默认会把“#”中间的变量作为字符串来处理。这样,就会出现这样的SQL

update user set flag='1' where id in ('1,2,3')  

所以使用$将你的变量括起来,iBATIS不会给这个变量做任何的处理,直接生成你要的SQL

update user set flag=$flag$ where id in ($id$)

update user set flag=1  where id in (1,2,3)  

猜你喜欢

转载自masong1987.iteye.com/blog/1310327
今日推荐