區別:
#{},用于傳遞參數,相當于一個占位符,可以防止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>新聞熱點
疑難解答