<?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.amms.mapper.ItemCollectionMapper">

    <resultMap type="com.amms.domain.ItemCollection" id="ItemCollectionResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="itemId"    column="item_id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectItemCollectionVo">
        select id, user_id, item_id, create_time from item_collection
    </sql>

    <select id="selectItemCollectionList" parameterType="com.amms.domain.ItemCollection" resultMap="ItemCollectionResult">
        <include refid="selectItemCollectionVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="itemId != null "> and item_id = #{itemId}</if>
        </where>
    </select>

    <select id="selectItemCollectionById" parameterType="Long" resultMap="ItemCollectionResult">
        <include refid="selectItemCollectionVo"/>
        where id = #{id}
    </select>

    <insert id="insertItemCollection" parameterType="com.amms.domain.ItemCollection" useGeneratedKeys="true" keyProperty="id">
        insert into item_collection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="itemId != null">item_id,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateItemCollection" parameterType="com.amms.domain.ItemCollection">
        update item_collection
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteItemCollectionById" parameterType="Long">
        delete from item_collection where id = #{id}
    </delete>
</mapper>
