MyBatis注意事项
<!-- 特殊字符的处理: 1.转义字符 < 等于 < 2.CDATA区 --> <select id="selectBy" parameterType="int" resultMap="brandResultMap"> select * from tb_brand where id <![CDATA[ < ]]> #{id};
参数占位符
1. #{}: 会将其替换成?号
2. ${}: 拼sql。会存在SQL注入问题
Ps.使用时机: * 参数传递的时候:#{}
* 表名或者列名不固定的情况下:${} 会存在SQL注入问题
<!--参数类型:parameterType可以省略-->
<select id="selectById" parameterType="int" resultMap="brandResultMap"> select * from tb_brand where id = #{id}; </select>