mybatis按照id查询出来的顺序进行排序

  • Post author:
  • Post category:其他


service层

List<GoodsSpu> goodsSpuList = baseMapper.queryGoodsSpuListByOrderBySpuIdList(PageParam.initial(page, queryDto), MapUtils.buildKeyValueMap(“spuIdList”, orderBySpuIdList, “spuIdStr”, spuIdSb.substring(0, spuIdSb.length() – 1)));

mapper层

/**
 * 通过商品id查询商品列表
 * @param pagination
 * @param spuMap (spuIdList   spuIdStr商品id集合拼成的字符串)
 * @return
 */
List<GoodsSpu> queryGoodsSpuListByOrderBySpuIdList(Pagination pagination, Map<Object, Object> spuMap);

xml

<!-- 根据spuIdList的顺序查询出商品信息的列表 -->
<select id="queryGoodsSpuListByOrderBySpuIdList" parameterType="java.util.Map" resultType="GoodsSpu">
    select
    <include refid="Base_Column_List"/>
    from goods_spu where spu_id in
    <foreach collection="spuIdList" item="spuId" separator="," open="(" close=")">
        #{spuId}
    </foreach>
    and flag_del = 0
    order by field(
    spu_id, ${spuIdStr}
    )
</select>

通过查询出的id进行排序的方式。



版权声明:本文为weixin_40496774原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。