mybatis是如何防止SQL注入的

676
2021/1/7 16:46:33
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

mybatis是如何防止SQL注入的

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();

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: Mybatis使用CLOB字段存储XML好吗