MySQL users define their own sorting function
order by field(value1, id1,id2,id3,...) without limitation on parameter length.
Meaning: Sort the obtained values according to the order of id1, id2, id3...
Example: mybatis
select
<include refid="Base_Column_List"/>
from tb_newbee_mall_goods_info
where goods_id in
<foreach item="id" collection="list" open="(" separator="," close=")">
#{
id}
</foreach>
order by field(goods_id,
<foreach item="id" collection="list" separator=",">
#{
id}
</foreach>
);
The parameter passed in mybatis is a List array with id, the order of this array is already arranged, and mybatis is required to return data in the same order.