在我们操作MyBatis的时候,sql语句 输入参数时,需要用#{xx} 或 ${xx} 来传值
例如查学生Id:
<select id="queryStudentBySno" resultType="Student" parameterType="int">
select * from Student where id = #{id}
</select>
或者
<select id="queryStudentBySno" resultType="Student" parameterType="int">
select * from Student where id = ${value}
</select>
那么两者有什么区别呢?
a.当输入参数为8个基本类型+String的时候
#{任意值} 而 ${value} (只能写value)
b.#{} 会自动给String类型加上 ‘ ’ (自动类型转换)
而 ${} 则原样输出,但是适合于 动态排序(动态字段)