1. 程式人生 > >Mybatis 中 in 語法 的# 與 $區別

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