需求:更改指定一些客户的一个字段
设计:传参两个(一个需要更改字段,一个客户id字符串用","隔开)
问题:mybatis中sql语句里条件报错,原因是用了#{clientIds}传入sql中是字符串形式
where id in (#{clientIds})
等于 where id in ("1,2,3,4")
报错
解决:
方法1、客户id字符串在代码里分割成list,mybatis中list遍历
<foreach collection="clientIdList" item="item" index="index" open="(" separator="," close=")"> #{item} </foreach>
方法2、将字符串在mybatis里分割
<foreach collection="clientIds.split(',')" item="item" index="index" open="(" separator="," close=")"> #{item} </foreach>
方法3、sql注入,改为where id in (${clientIds})
mybatis传入分割字符串做参数
最新推荐文章于 2024-05-17 16:47:48 发布