123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?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.example.mapper.ProductMapper">
- <sql id="Base_Column_List">
- product.id,product_state,product_name,product_icons,product_type_ids,product_bid_price,product_sell_price
- </sql>
- <resultMap id="productWithProductType" type="com.example.entity.Product">
- <id property="id" column="id"></id>
- <result property="productState" column="product_state"/>
- <result property="productName" column="product_name"/>
- <result property="productIcons" column="product_icons"/>
- <result property="productBidPrice" column="product_bid_price"/>
- <result property="productSellPrice" column="product_sell_price"/>
- <result property="productTypeIds" column="product_type_ids" jdbcType="VARCHAR" typeHandler="com.example.typeHandler.ArrayIntegerTypeHadnler" />
- <!-- 店铺产品联合属性 List -->
- <collection property="productTypes" javaType="list" ofType="com.example.entity.ProductType">
- <id property="id" column="productTypeId"/>
- <result property="productTypeName" column="productTypeName"/>
- </collection>
- </resultMap>
- <select id="selectAll" resultMap="productWithProductType">
- select product.*,
- product_type.id as productTypeId,
- product_type_name as productTypeName
- from product
- left join product_type on JSON_CONTAINS(product.product_type_ids,CAST(product_type.id as JSON),'$')
- <where>
- <if test="id != null"> and product.id = #{id}</if>
- <if test="productState != null"> and product_state like concat('%', #{productState}, '%')</if>
- <if test="productName != null"> and product_name like concat('%', #{productName}, '%')</if>
- <if test="productIcons != null"> and product_icons like concat('%', #{productIcons}, '%')</if>
- <if test="productTypeIds != null"> and product_type_ids like concat('%', #{productIds,jdbcType=VARCHAR,typeHandler=com.example.typeHandler.ArrayIntegerTypeHadnler}, '%')</if>
- <if test="productBidPrice != null"> and product_bid_price = #{productBidPrice}</if>
- <if test="productSellPrice != null"> and product_sell_price = #{productSellPrice}</if>
- </where>
- order by product_type.id desc
- </select>
- <select id="selectById" resultType="com.example.entity.Product">
- select
- <include refid="Base_Column_List" />
- from product
- where id = #{id}
- </select>
- <select id="selectByStoreId" resultType="com.example.entity.Product">
- select product.*, store.id as storeId
- from store
- left join product on JSON_CONTAINS(store.products_ids,CAST(product.id as JSON),'$')
- where store.id = #{storeId}
- </select>
- <delete id="deleteById">
- delete from product
- where id = #{id}
- </delete>
- <insert id="insert" parameterType="com.example.entity.Product" useGeneratedKeys="true" keyProperty="id">
- insert into product
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="id != null">id,</if>
- <if test="productState != null">product_state,</if>
- <if test="productName != null">product_name,</if>
- <if test="productIcons != null">product_icons,</if>
- <if test="productTypeIds != null">product_type_ids,</if>
- <if test="productBidPrice != null">product_bid_price,</if>
- <if test="productSellPrice != null">product_sell_price,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="id != null">#{id},</if>
- <if test="productState != null">#{productState},</if>
- <if test="productName != null">#{productName},</if>
- <if test="productIcons != null">#{productIcons},</if>
- <if test="productTypeIds != null">#{productTypeIds},</if>
- <if test="productBidPrice != null">#{productBidPrice},</if>
- <if test="productSellPrice != null">#{productSellPrice},</if>
- </trim>
- </insert>
- <update id="updateById" parameterType="com.example.entity.Product">
- update product
- <set>
- <if test="productState != null">
- product_state = #{productState},
- </if>
- <if test="productName != null">
- product_name = #{productName},
- </if>
- <if test="productIcons != null">
- product_icons = #{productIcons},
- </if>
- <if test="productTypeIds != null">
- product_type_ids = #{productTypeIds,jdbcType=VARCHAR,typeHandler=com.example.typeHandler.ArrayIntegerTypeHadnler},
- </if>
- <if test="productBidPrice != null">
- product_bid_price = #{productBidPrice},
- </if>
- <if test="productSellPrice != null">
- product_sell_price = #{productSellPrice},
- </if>
- </set>
- where id = #{id}
- </update>
- </mapper>
|