<?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.tao.mapper.AppPageMapper">

    <resultMap type="AppPage" id="AppPageResult">
        <result property="pageID" column="page_id"/>
        <result property="pageName" column="page_name"/>
        <result property="pageClassName" column="page_class_name"/>
    </resultMap>

    <sql id="selectAppPageVo">
        select page_id,
               page_name,
               page_class_name
        from app_page
    </sql>

    <select id="selectAppPageById" parameterType="Long" resultMap="AppPageResult">
        <include refid="selectAppPageVo"/>
        where page_id = #{pageID}
    </select>

    <select id="selectAppPageByName" parameterType="String" resultMap="AppPageResult">
        <include refid="selectAppPageVo"/>
        where page_name = #{pageName}
    </select>

    <select id="selectAppPageList" parameterType="AppPage" resultMap="AppPageResult">
        <include refid="selectAppPageVo"/>
        <where>
            <if test="pageID != null  and pageID != ''">and page_id = #{pageID}</if>
            <if test="pageName != null  and pageName != ''">and page_name = #{pageName}</if>
            <if test="pageClassName != null  and pageClassName != ''">and page_class_name = #{pageClassName}</if>
        </where>
    </select>

    <insert id="insertAppPage" parameterType="AppPage" useGeneratedKeys="true" keyProperty="pageID">
        insert into app_page
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pageName != null">page_name,</if>
            <if test="pageClassName != null">page_class_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pageName != null">#{pageName},</if>
            <if test="pageClassName != null">#{pageClassName},</if>
        </trim>
    </insert>

    <update id="updateAppPage" parameterType="AppPage">
        update app_page
        <trim prefix="SET" suffixOverrides=",">
            <if test="pageName != null">page_name = #{pageName},</if>
            <if test="pageClassName != null">page_class_name = #{pageClassName},</if>
        </trim>
        where page_id = #{pageID}
    </update>

    <delete id="deleteAppPageById" parameterType="Long">
        delete
        from app_page
        where page_id = #{pageID}
    </delete>

    <delete id="deleteAll" parameterType="Long">
        delete
        from app_page
    </delete>

</mapper>