<?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.javaclimb.music.dao.SingerMapper">
    <resultMap id="BaseResultMap" type="com.javaclimb.music.domain.Singer" >
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="sex" jdbcType="TINYINT" property="sex"/>
        <result column="pic" jdbcType="VARCHAR" property="pic"/>
        <result column="birth" jdbcType="TIMESTAMP" property="birth"/>
        <result column="location" jdbcType="VARCHAR" property="location"/>
        <result column="introduction" jdbcType="VARCHAR" property="introduction"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,name,sex,pic,birth,location,introduction
    </sql>

    <insert id="insert" parameterType="com.javaclimb.music.domain.Singer">
        insert into singer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="sex != null">
                sex,
            </if>
            <if test="pic != null">
                pic,
            </if>
            <if test="birth != null">
                birth,
            </if>
            <if test="location != null">
                location,
            </if>
            <if test="introduction != null">
                introduction,
            </if>
        </trim>
        <trim prefix=" values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="name != null">
                #{name},
            </if>
            <if test="sex != null">
                #{sex},
            </if>
            <if test="pic != null">
                #{pic},
            </if>
            <if test="birth != null">
                #{birth},
            </if>
            <if test="location != null">
                #{location},
            </if>
            <if test="introduction != null">
                #{introduction},
            </if>
        </trim>        
    </insert>
    
    <update id="update" parameterType="com.javaclimb.music.domain.Singer">
        update singer
        <set>
            <if test="name != null">
                name = #{name},
            </if>
            <if test="sex != null">
                sex = #{sex},
            </if>
            <if test="pic != null">
                pic = #{pic},
            </if>
            <if test="birth != null">
                birth = #{birth},
            </if>
            <if test="location != null">
                location = #{location},
            </if>
            <if test="introduction != null">
                introduction = #{introduction},
            </if>
        </set>
        where id = #{id}
    </update>

    <delete id="delete" parameterType="java.lang.Integer">
        delete from singer
        where id=#{id}
    </delete>

    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from singer
        where id=#{id}
    </select>

    <select id="allSinger" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from singer
    </select>

    <select id="singerOfName" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from singer
        where name like #{name}
    </select>

    <select id="singerOfSex" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from singer
        where sex = #{sex}
    </select>

</mapper>
















