<?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.SongListMapper">
    <resultMap id="BaseResultMap" type="com.javaclimb.music.domain.SongList" >
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="title" jdbcType="VARCHAR" property="title"/>
        <result column="pic" jdbcType="VARCHAR" property="pic"/>
        <result column="style" jdbcType="VARCHAR" property="style"/>
    </resultMap>

    <resultMap id="ResultMapWithBLOBs" type="com.javaclimb.music.domain.SongList" extends="BaseResultMap">
        <result column="introduction" jdbcType="LONGVARCHAR" property="introduction"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,title,pic,style
    </sql>

    <sql id="Blob_Column_List">
        id,title,pic,style,introduction
    </sql>

    <insert id="insert" parameterType="com.javaclimb.music.domain.SongList">
        insert into song_list
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="title != null">
                title,
            </if>
            <if test="pic != null">
                pic,
            </if>
            <if test="introduction != null">
                introduction,
            </if>
            <if test="style != null">
                style,
            </if>
        </trim>
        <trim prefix=" values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="title != null">
                #{title},
            </if>
            <if test="pic != null">
                #{pic},
            </if>
            <if test="introduction != null">
                #{introduction},
            </if>
            <if test="style != null">
                #{style},
            </if>
        </trim>        
    </insert>
    
    <update id="update" parameterType="com.javaclimb.music.domain.SongList">
        update song_list
        <set>
            <if test="title != null">
                title = #{title},
            </if>
            <if test="pic != null">
                pic = #{pic},
            </if>
            <if test="introduction != null">
                introduction = #{introduction},
            </if>
            <if test="style != null">
                style = #{style},
            </if>
        </set>
        where id = #{id}
    </update>

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

    <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer">
        select
        <include refid="Blob_Column_List"/>
        from song_list
        where id=#{id}
    </select>

    <select id="allSongList" resultMap="ResultMapWithBLOBs">
        select
        <include refid="Blob_Column_List"/>
        from song_list
    </select>

    <select id="songListOfTitle" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String">
        select
        <include refid="Blob_Column_List"/>
        from song_list
        where title = #{title}
    </select>

    <select id="likeTitle" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String">
        select
        <include refid="Blob_Column_List"/>
        from song_list
        where title like #{title}
    </select>

    <select id="likeStyle" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String">
        select
        <include refid="Blob_Column_List"/>
        from song_list
        where style like #{style}
    </select>

</mapper>
















