mybatis bind标签

使用bind拼接字符串不仅可以避免因更换数据库而修改 SQL,也能预防 SQL 注入

示例,oracle的concat只能支持2个参数相连,下面语句只能在mysql能成功:

<if test="userName != null and userName!=''">
          and user_name like concat('%',#{userName},'%')
</if>

使用bind示例,各数据库通用,除了兼容性,还比上面的优势有预防SQL注入

 <if test="userName != null and userName!=''">
            <bind name="pattern" value="'%'+userName+'%'" />
          AND UPPER(user_name) LIKE UPPER(#{pattern})
</if>
posted @ 2021-09-26 21:24  码农公子的幸福生活  阅读(188)  评论(0)    收藏  举报