先来一段变态代码:
<select id="selectSerial" parameterType="PageData" resultType="PageData">
select
cs_id,
bs_id,
cb_id,
cs_show_name,
cb_Name,
mb_Name,
logo,
cs_pic,
country,
type,
displacement,
level,
max_price,
min_price,
create_by,
update_by,
create_time,
update_time,
is_deleted,
dealer_update_time,
CsPriceRange
FROM car_serial WHERE 1=1
<if test="cb_Name != '' and cb_Name != null">
<if test="cb_Name == '丰田'">
and cb_id in(20057, 10020)
</if>
<if test="cb_Name != '丰田'">
and cb_Name LIKE '%${cb_Name}%'
</if>
</if>
<if test="level != '' and level != null">
and `level` like #{level}
</if>
AND cs_pic != 'http://image.bitautoimg.com/autoalbum/V2.1/images/150-100.gif'
<if test="cb_Name == '奥迪'">
order by cb_id
</if>
<if test="cb_Name == '宝马'">
order by FIELD(`cb_id`, '20066', '20218', '20005')
</if>
</select>
自定义排序可以根据字段里的数据进行排序,实在是太好用了
语法如下:
order by FIELD(`cb_id`, '20066', '20218', '20005')