<?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="test05.mapper.TeacherMapper">
    <select id="selectTeacher" resultType="test05.pojo.Teacher">
        SELECT N_TEACHER_ID AS id,
               VC_TEACHER_NAME AS name,
               N_SEX AS sex,
               VC_BIRTH AS birth,
               N_EDUC AS educ,
               N_TITLE AS title
        FROM t_teacher
        WHERE #{teacher.id} in (N_TEACHER_ID, -1)
        AND VC_TEACHER_NAME LIKE CONCAT('%', #{teacher.name}, '%')
        AND #{teacher.sex} in (N_SEX, -1)
        AND #{teacher.educ} in (N_EDUC, -1)
        AND #{teacher.title} in (N_TITLE, -1)
        ORDER BY N_TEACHER_ID DESC
        LIMIT #{offset},#{pageSize};
    </select>
    <select id="selectTeacherCount" resultType="int">
        SELECT COUNT(*)
        FROM t_teacher
        WHERE #{id} in (N_TEACHER_ID, -1)
        AND VC_TEACHER_NAME LIKE CONCAT('%', #{name}, '%')
        AND #{sex} in (N_SEX, -1)
        AND #{educ} in (N_EDUC, -1)
        AND #{title} in (N_TITLE, -1);
    </select>
    <insert id="insertTeacher" keyProperty="N_TEACHER_ID" useGeneratedKeys="true">
        INSERT INTO t_teacher
            (VC_TEACHER_NAME, N_SEX, VC_BIRTH, N_EDUC, N_TITLE)
        VALUES (#{name},#{sex},#{birth},#{educ},#{title});
    </insert>
    <update id="updateTeacher">
        UPDATE t_teacher
        SET VC_TEACHER_NAME=#{name},
            N_SEX=#{sex},
            VC_BIRTH=#{birth},
            N_EDUC=#{educ},
            N_TITLE=#{title}
        WHERE N_TEACHER_ID=#{N_TEACHER_ID};
    </update>
    <delete id="deleteTeacher">
        DELETE FROM t_teacher
        WHERE N_TEACHER_ID = #{id};
    </delete>
</mapper>