首页 > 学院 > 开发设计 > 正文

mybatis中#{}和${}的区别于用法

2019-11-08 02:30:28
字体:
来源:转载
供稿:网友

区别:

#{},用于传递参数,相当于一个占位符,可以防止sql注入,安全;

${},用于sql的拼接,常用语group by,order by等不能使用占位符的语句中;

用法:

#{}

<if test="condition.userId != null and condition.userId != ''">       AND user_id = #{condition.userId  ,jdbcType=VARCHAR}  </if>  

${}

<select id="get" parameterType="java.util.Map" resultMap="test">    SELECT      <include refid="sql_column_list" />    FROM test    <trim PRefix="WHERE" prefixOverrides="AND">      <include refid="sql_condition" />    </trim>      <if test="orderBy != null">      ORDER BY ${orderBy}    </if>     LIMIT 1  </select> 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表