mybatis动态传入order by(排序字段)
一版形式
SELECT <include refid="Base_Column_List"/>
FROM alarm_list_info_view as m
<where>
m.status = 0
</where>
order by ${param.orderBy} ${param.sort}
防止注入
SELECT <include refid="Base_Column_List"/>
FROM alarm_list_info_view as m
<where>
<if test="param.orderBy== 'begin_time'">
order by begin_time
</if>
<if test="param.orderBy== 'update_time'">
order by update_time
</if>
</where>
SELECT * FROM alarm_list_info_view as m
<choose>
<when test="(orderBy=='begin_time' or orderBy=='update_time') and (sort=='desc' or sort=='asc')">
order by ${orderBy} ${sort}
</when>
<otherwise>
order by updateTime desc
</otherwise>
</choose>