hong2k1 2012-10-14 19:29
浏览 257
已采纳

这样的SQL会有被注入的危险么?

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mybatis.config.UserDao">
<select id="findUser" parameterType="int" resultType="com.mybatis.config.User">
     select * from user where 0=0
<if test="userName != null"> 
and userName = #{userName,jdbcType=VARCHAR}
</if> 
<if test="password != null"> 
and password = #{password,jdbcType=VARCHAR}
</if> 
<if test="comment != null"> 
and comment = #{comment,jdbcType=VARCHAR}
</if> 
</select>
</mapper>

 现在有个需求,就是根据表的任何属性来查询查找记录,项目没有用到hibernate,想用mybatis来做,我想问的就是:下面这样的配置会有被注入的危险么?因为mybatis的sql好像也是拼出来的。

  • 写回答

5条回答

  • jinnianshilongnian 2012-10-14 19:45
    关注

    #{password,jdbcType=VARCHAR} 会在mapper时 自动用?替代 即用占位符

    ${password} 这种是有sql注入问题 因为是直接拼字符串方式实现

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?