<?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.LinkDao">
    <resultMap id="LinkResult" type="Link">
        <result property="id" column="id"/>
        <result property="linkName" column="linkName"/>
        <result property="linkUrl" column="linkUrl"/>
        <result property="orderNo" column="orderNo"/>
    </resultMap>

    <select id="findById" parameterType="Integer" resultMap="LinkResult">
        select *
        from t_Link
        where id = #{id}
    </select>

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

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

    <insert id="add" parameterType="Link">
        insert into t_Link(linkName, linkUrl, orderNo)
        values (#{linkName}, #{linkUrl}, #{orderNo})
    </insert>

    <update id="update" parameterType="Link">
        update t_link
        <set>
            <if test="linkName!=null and linkName!=''">
               linkName=#{linkName},
            </if>
            <if test="linkUrl!=null and linkName!=''">
               linkUrl=#{linkUrl},
            </if>
            <if test="orderNo!=null">
                orderNo=#{orderNo},
            </if>
        </set>
        where id=#{id}
    </update>

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

</mapper>