ORDER BY clause is not working properly

用户可以自己在前端选择字段,动态排序。用MyBatis,SQL如下。发现ORDER BY没有起作用。

 <select id="selectBudgetCategoryList" resultMap="BaseResultMap" parameterType="com.xxx.ConfigSearchParam">

  <include refid="pageHeader"/>
    select
    <include refid="Base_Column_List" />
    from EMR_BUDGET_CATEGORY
    where 1=1
    <if test="id != null and id != 0" >
      and BUDGET_CATEGORY_REF_ID = #{id,jdbcType=DECIMAL}
    </if>
    <if test="name != null" >
      and UPPER(BUDGET_CATEGORY) LIKE '%'||UPPER(#{name,jdbcType=VARCHAR})||'%'
    </if>
    <if test="deleteFlag != null" >
      and DELETE_FLAG = #{deleteFlag,jdbcType=CHAR}
    </if>
    <if test="sortOrder != null and sortOrder != ''" >
      order by #{sortOrder,jdbcType=VARCHAR}
    </if>
    <include refid="pageFoot"/>

  </select>

调查结果如下:

#{} is used to put a parameter. This is the same as using ? in a PreparedStatement. 
${} is string substitution. It doesn't use any parameter. This is the one that opens you to SQL injection. 
To prevent SQL injection, the best thing to do is always use #{} when possible. 
When you need to use ${}, make sure that the value is given by your code (usually a constant) and not by a user. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值