mybatis避免SQL注入的方法:
mybatis在框架底层,是JDBC中的PreparedStatement类在起作用,因此mybatis启用了预编译功能,从而下降了SQL注入的风险,例如:
//安全的,预编译了的
Connection conn = getConn();//取得连接
String sql = "select id, username, password, role from user where id=?"; //履行sql前会预编译号该条语句
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
ResultSet rs=pstmt.executeUpdate();
本文来源:https://www.yuntue.com/post/62048.html | 云服务器网,转载请注明出处!

微信扫一扫打赏
支付宝扫一扫打赏