mybatis自定义排序 order by case when

以衣服尺码为例

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.benefm.mapper.ProductMapper">
   <select id="findAllProduct" resultMap="productMap">
		select p.id as id,p.create_time as create_time, p.name as name,p.price as price,p.cover_pic as cover_pic, p.product_pic as product_pic, p.type as type,p1.name as productSizeName ,p1.stock_amount as stock_amount,p1.sales_amount as sales_amount,p1.id as productSizeId,p1.create_time as p_create_time,p1.product_id as product_id from  product p left
      join product_size p1 on p.id=p1.product_id  order by 
     case when p1.name='M' then 0
      when p1.name='L' then 1
      when p1.name='XL' then 2
      when p1.name='XXL' then 3
      when p1.name='XXXL' then 4
      when p1.name='XXXXL' then 5
      end ASC  limit ${(page-1)*pageSize},${pageSize};
	</select>

	<resultMap id="productMap" type="com.benefm.entity.Product">
		<result property="id" column="id"/>
        <result property="name" column="name"/>
		<result property="type" column="type"/>
		<result property="cover_pic" column="cover_pic"/>
		<result property="product_pic" column="product_pic"/>
		<result property="price" column="price"/>
		<result property="create_time" column="create_time"/>
		<collection property="productSizeList" ofType="com.benefm.entity.ProductSize">
			<result property="id" column="productSizeId"/>
			<result property="name" column="productSizeName"/>
			<result property="product_id" column="product_id"/>
			<result property="stock_amount" column="stock_amount"/>
			<result property="sales_amount" column="sales_amount"/>
			<result property="create_time" column="p_create_time"/>
		</collection>
	</resultMap>
	</mapper>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值