聊聊SQL注入( 二 )

select * from users where name like concat('%',#{name}, '%')

  • 补充:
    • in 之后的多个参数在mybatis中也不能采用 #{} 或者 ${} ,需要使用动态SQL语法中 foreach 循环遍历
      select * from users where id in<foreach collection="ids" item="item" open="("separatosr="," close=")"> #{item}</foreach>
    • order by 之后也不能使用 #{},他也会将字段改为字符串形式,加上引号后就不能正常排序,所以我们需要考虑 ${} 的方式,但是在后台代码中一定要进行数据参数的校验等手段,防止SQL注入.
  • 经验总结扩展阅读