<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.ftebox.dao.BloggerDao">
    <resultMap id="BloggerResult" type="Blogger">
        <result property="id" column="id"/>
        <result property="userName" column="userName"/>
        <result property="password" column="password"/>
        <result property="nickName" column="nickName"/>
        <result property="sign" column="sign"/>
        <result property="profile" column="profile"/>
        <result property="imageName" column="imageName"/>
    </resultMap>
    <select id="getByUserName" parameterType="String" resultMap="BloggerResult">
        select *
        from t_blogger
        where userName = #{userName}
    </select>

    <insert id="insert" parameterType="Blogger">
        insert into t_blogger(userName, password)
        values (#{userName}, #{password})
    </insert>

    <update id="update" parameterType="Blogger">
        update t_blogger
        <set>
            <if test="password!=null and password!=''">
                password=#{password},
            </if>
            <if test="nickName!=null and nickName!=''">
                nickName=#{nickName},
            </if>
            <if test="sign!=null and sign!=''">
                sign=#{sign},
            </if>
            <if test="profile!=null and profile!=''">
                profile=#{profile},
            </if>
            <if test="imageName!=null and imageName!=''">
                imageName=#{imageName},
            </if>
            <if test="userTag!=null">
                userTag=#{userTag},
            </if>
        </set>
        where id=#{id}
    </update>

    <select id="find" resultMap="BloggerResult">
        select *
        from t_blogger limit 1
    </select>

    <select id="list" parameterType="Map" resultMap="BloggerResult">
        select * from t_blogger
        order by id
        <if test="start!=null and size!=null">
            limit #{start},${size}
        </if>
    </select>

    <select id="getTotal" parameterType="Integer" resultType="long">
        select count(*)
        from t_blogger
    </select>

    <delete id="delete" parameterType="Integer">
        delete
        from t_blogger
        where id = #{id}
    </delete>

</mapper>