#:是占位符
#{}组合会被置换成?
比如说:
<select id="selectStudentById" resultType="">
select id,name,email,age from student where id=#{studentId}
</select>
Mybatis在执行的时候会将#{studentId}整体替换成?
即变成:
<select id="selectStudentById" resultType="">
select id,name,email,age from student where id=?
</select>
然后后面调用这条sql语句的时候,?就会被换成对应的参数
Student student=dao.selectStudyById(1005)
相当于执行:
select id,name,email,age from student where id=1005
$:
<select id="selectStudentById" resultType="">
select id,name,email,age from student where id=${studentId}
</select>
Student student=dao.selectStudyById(1005)
最后也会得到
select id,name,email,age from student where id=1005
但是能用井号尽量用井号,不要用刀乐符号