首页 > 技术文章 > mybatis使用order by注意

firebata 2015-05-07 11:45 原文

直接用动态参数生成,不会排序:

<if test="orderColumn!=null and orderColumn != ''">
ORDER BY #{orderColumn} #{orderDir}
</if>

需要将#改为$:

<if test="orderColumn!=null and orderColumn != ''">
ORDER BY ${orderColumn} ${orderDir}
</if>

推荐阅读