#{ } select * from user where id = ? 占位符 ?==’ ’
$ { } select * from user where username like 字符串拼接
select * from user where username like ‘%$ {value}%’ 不防止sql注入,可改为
select * from user where username like “%”#{value}"%"
Mappper动态代理开发
遵循四原则:
- Mapper.xml文件中的namespace与mapper接口的类路径相同。
- Mapper接口方法名和Mapper.xml中定义的每个statement的id相同
- Mapper接口的方法的输入类型和mapper.xml中定义的每个sql的parameterType的类型相同
- Mapper接口方法的输出参数类型和mapper.xml中定义的每个sql的resultType的类型相同。