SELECT
*
FROM
t_goods
WHERE
id
IN(
<foreach collection="array" item="item" separator=",">
#{item}
</foreach>
)
ORDER BY
FIELD(id,
<foreach collection="array" item="item" separator=",">
#{item}
</foreach>
)
重点是排序加上FIELD与主键id, 就可以达到查询结果与in传入的参数顺序一致效果。