MySQL用户自定义排序函数——order by field 在Mybatis中实现

MySQL用户自己定义排序函数
order by field(value1, id1,id2,id3,…) 不限制参数长度。
含义:将获取到的值根据id1,id2,id3…的顺序排序。
例子: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>
        );

mybatis中传的参数为一个带有id的List数组,这个数组的顺序已经是排好的了,要求mybatis返回一样的顺序的数据。

猜你喜欢

转载自blog.csdn.net/weixin_43663421/article/details/109339736