<?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.ConsumerMapper">
    <resultMap id="BaseResultMap" type="com.javaclimb.music.domain.Consumer" >
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="username" jdbcType="VARCHAR" property="username"/>
        <result column="password" jdbcType="VARCHAR" property="password"/>
        <result column="sex" jdbcType="TINYINT" property="sex"/>
        <result column="phone_num" jdbcType="CHAR" property="phoneNum"/>
        <result column="email" jdbcType="CHAR" property="email"/>
        <result column="birth" jdbcType="TIMESTAMP" property="birth"/>
        <result column="introduction" jdbcType="VARCHAR" property="introduction"/>
        <result column="location" jdbcType="VARCHAR" property="location"/>
        <result column="avator" jdbcType="VARCHAR" property="avator"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,username,password,sex,phone_num,email,birth,introduction,location,avator,create_time,update_time
    </sql>

    <insert id="insert" parameterType="com.javaclimb.music.domain.Consumer">
        insert into consumer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="username != null">
                username,
            </if>
            <if test="password != null">
                password,
            </if>
            <if test="sex != null">
                sex,
            </if>
            <if test="phoneNum != null">
                phone_num,
            </if>
            <if test="email != null">
                email,
            </if>
            <if test="birth != null">
                birth,
            </if>
            <if test="introduction != null">
                introduction,
            </if>
            <if test="location != null">
                location,
            </if>
            <if test="avator != null">
                avator,
            </if>
            create_time,update_time,
        </trim>
        <trim prefix=" values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="username != null">
                #{username},
            </if>
            <if test="password != null">
                #{password},
            </if>
            <if test="sex != null">
                #{sex},
            </if>
            <if test="phoneNum != null">
                #{phoneNum},
            </if>
            <if test="email != null">
                #{email},
            </if>
            <if test="birth != null">
                #{birth},
            </if>
            <if test="introduction != null">
                #{introduction},
            </if>
            <if test="location != null">
                #{location},
            </if>
            <if test="avator != null">
                #{avator},
            </if>
            now(),now(),
        </trim>        
    </insert>
    
    <update id="update" parameterType="com.javaclimb.music.domain.Consumer">
        update consumer
        <set>
            <if test="username != null">
                username = #{username},
            </if>
            <if test="password != null">
                password = #{password},
            </if>
            <if test="sex != null">
                sex = #{sex},
            </if>
            <if test="phoneNum != null">
                phone_num = #{phoneNum},
            </if>
            <if test="email != null">
                email = #{email},
            </if>
            <if test="birth != null">
                birth = #{birth},
            </if>
            <if test="introduction != null">
                introduction = #{introduction},
            </if>
            <if test="location != null">
                location = #{location},
            </if>
            <if test="avator != null">
                avator = #{avator},
            </if>
            update_time = now(),
        </set>
        where id = #{id}
    </update>

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

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

    <select id="allConsumer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from consumer
    </select>

    <select id="verifyPassword" resultType="java.lang.Integer" parameterType="java.util.HashMap">
        select count(*)
        from consumer
        where username = #{username} and password = #{password}
    </select>

    <select id="getByUsername" resultMap="BaseResultMap" parameterType="java.lang.String">
        select
        <include refid="Base_Column_List"/>
        from consumer
        where username = #{username}
    </select>

</mapper>
















