63 lines
2.3 KiB
XML
63 lines
2.3 KiB
XML
<?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.meiruo.cosmetics.mapper.CartMapper">
|
|
|
|
<resultMap id="BaseResultMap" type="com.meiruo.cosmetics.entity.Cart">
|
|
<id column="id" property="id"/>
|
|
<result column="user_id" property="userId"/>
|
|
<result column="product_id" property="productId"/>
|
|
<result column="quantity" property="quantity"/>
|
|
<result column="create_time" property="createTime"/>
|
|
<result column="update_time" property="updateTime"/>
|
|
</resultMap>
|
|
|
|
<resultMap id="CartWithProductResultMap" type="java.util.Map">
|
|
<id column="id" property="id"/>
|
|
<result column="user_id" property="userId"/>
|
|
<result column="product_id" property="productId"/>
|
|
<result column="quantity" property="quantity"/>
|
|
<result column="product_name" property="productName"/>
|
|
<result column="product_price" property="productPrice"/>
|
|
<result column="product_image" property="productImage"/>
|
|
</resultMap>
|
|
|
|
<select id="selectByUserAndProduct" resultMap="BaseResultMap">
|
|
SELECT * FROM cart WHERE user_id = #{userId} AND product_id = #{productId}
|
|
</select>
|
|
|
|
<select id="selectByUserId" resultMap="CartWithProductResultMap">
|
|
SELECT c.id, c.user_id, c.product_id, c.quantity,
|
|
p.name as product_name, p.price as product_price, p.image as product_image
|
|
FROM cart c
|
|
LEFT JOIN product p ON c.product_id = p.id
|
|
WHERE c.user_id = #{userId}
|
|
</select>
|
|
|
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
|
INSERT INTO cart (user_id, product_id, quantity, create_time, update_time)
|
|
VALUES (#{userId}, #{productId}, #{quantity}, NOW(), NOW())
|
|
</insert>
|
|
|
|
<update id="update">
|
|
UPDATE cart
|
|
<set>
|
|
<if test="quantity != null">quantity = #{quantity},</if>
|
|
update_time = NOW()
|
|
</set>
|
|
WHERE id = #{id}
|
|
</update>
|
|
|
|
<delete id="delete">
|
|
DELETE FROM cart WHERE id = #{id}
|
|
</delete>
|
|
|
|
<delete id="deleteByUserId">
|
|
DELETE FROM cart WHERE user_id = #{userId}
|
|
</delete>
|
|
|
|
<update id="updateQuantity">
|
|
UPDATE cart SET quantity = #{quantity}, update_time = NOW() WHERE id = #{id}
|
|
</update>
|
|
|
|
</mapper>
|