<?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">
<!--namespace 命名空间-->
<mapper namespace="com.sf.mapper.TeaMapper">
    <!--
        <insert>标签，插入SQL
        id 唯一标识
        parameterType 参数对象类型
    -->
    <insert id="insert" parameterType="tea">
        INSERT INTO tea
        VALUES (#{id},#{teaName},#{teaTypeId},#{ordered},#{description},#{status})
    </insert>


    <!--
        <update>标签，修改功能标签
        id 唯一标识
        parameterType 参数对象类型
        resultType 指定结果 映射的对象类型
    -->
    <update id="update" parameterType="tea">
        UPDATE tea SET
                       teaName=#{teaName},
                       teaTypeId=#{teaTypeId},
                       ordered=#{ordered},
                       description=#{description},
                       status=#{status}
        WHERE id=#{id}
    </update>
    <!--
        <delete> 删除功能标签
    -->
    <delete id="delete" parameterType="integer">
        DELETE FROM tea WHERE id=#{id}
    </delete>

    <!--查询所有茶叶信息-->
    <!--
        select标签 查询功能的标签
        id属性 唯一标识，对应Mapper接口中的方法名
        resultType 指定查询结果的映射对象类型
        parameterType   指定参数的映射对象类型
    -->
    <select id="selectAll" resultType="com.sf.entity.Tea" >
        SELECT * FROM tea
    </select>

    <select id="selectById" resultType="com.sf.entity.Tea" parameterType="integer">
        SELECT * FROM tea WHERE id=#{id}
    </select>

    <select id="selectByCondition" resultType="tea" parameterType="tea">
        SELECT * FROM tea
        <where>
            <if test="id!=null">
                id=#{id}
            </if>
            <if test="teaName!=null">
                AND teaName=#{teaName}
            </if>
            <if test="description!=null">
                AND description=#{description}
            </if>
        </where>
    </select>

    <select id="selectByIds" resultType="com.sf.entity.Tea">
        SELECT * FROM tea
        <where>
            <foreach collection="list" open="id IN(" close=")" item="id" separator=",">
                #{id}
            </foreach>
        </where>
    </select>

</mapper>