#{}
预编译SQL语句再取值,以?的占位符形式,可以防止SQL注入。通过JDBC的PreparedStatement新建对象,对应SQL语句:
select * from t_user where username = ?
${}
取值后再编译SQL语句,相当于字符串拼接,无法防止SQL注入。通过JDBC的Statement新建对象,对应SQL语句:
select * from t_user where username = '"+username+"'
注:
在原生JDBC里不支持占位符的的SQL语句中,我们就只能用 ${} 。例如:
delete from t_user where id in (${ids})
select * from t_user order by ${create_time}