<?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.ruoyi.demo.mapper.DemoStudentMapper">
    
    <resultMap type="DemoStudent" id="DemoStudentResult">
        <result property="studentId"    column="student_id"    />
        <result property="studentName"    column="student_name"    />
        <result property="studentAge"    column="student_age"    />
        <result property="studentHobby"    column="student_hobby"    />
        <result property="studentSex"    column="student_sex"    />
        <result property="studentStatus"    column="student_status"    />
        <result property="studentBirthday"    column="student_birthday"    />
    </resultMap>

    <sql id="selectDemoStudentVo">
        select student_id, student_name, student_age, student_hobby, student_sex, student_status, student_birthday from demo_student
    </sql>

    <select id="selectDemoStudentList" parameterType="DemoStudent" resultMap="DemoStudentResult">
        <include refid="selectDemoStudentVo"/>
        <where>  
            <if test="studentName != null  and studentName != ''"> and student_name like concat('%', #{studentName}, '%')</if>
            <if test="studentAge != null "> and student_age = #{studentAge}</if>
        </where>
    </select>
    
    <select id="selectDemoStudentByStudentId" parameterType="Long" resultMap="DemoStudentResult">
        <include refid="selectDemoStudentVo"/>
        where student_id = #{studentId}
    </select>
        
    <insert id="insertDemoStudent" parameterType="DemoStudent" useGeneratedKeys="true" keyProperty="studentId">
        insert into demo_student
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="studentName != null and studentName != ''">student_name,</if>
            <if test="studentAge != null">student_age,</if>
            <if test="studentHobby != null and studentHobby != ''">student_hobby,</if>
            <if test="studentSex != null and studentSex != ''">student_sex,</if>
            <if test="studentStatus != null and studentStatus != ''">student_status,</if>
            <if test="studentBirthday != null">student_birthday,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="studentName != null and studentName != ''">#{studentName},</if>
            <if test="studentAge != null">#{studentAge},</if>
            <if test="studentHobby != null and studentHobby != ''">#{studentHobby},</if>
            <if test="studentSex != null and studentSex != ''">#{studentSex},</if>
            <if test="studentStatus != null and studentStatus != ''">#{studentStatus},</if>
            <if test="studentBirthday != null">#{studentBirthday},</if>
         </trim>
    </insert>

    <update id="updateDemoStudent" parameterType="DemoStudent">
        update demo_student
        <trim prefix="SET" suffixOverrides=",">
            <if test="studentName != null and studentName != ''">student_name = #{studentName},</if>
            <if test="studentAge != null">student_age = #{studentAge},</if>
            <if test="studentHobby != null and studentHobby != ''">student_hobby = #{studentHobby},</if>
            <if test="studentSex != null and studentSex != ''">student_sex = #{studentSex},</if>
            <if test="studentStatus != null and studentStatus != ''">student_status = #{studentStatus},</if>
            <if test="studentBirthday != null">student_birthday = #{studentBirthday},</if>
        </trim>
        where student_id = #{studentId}
    </update>

    <delete id="deleteDemoStudentByStudentId" parameterType="Long">
        delete from demo_student where student_id = #{studentId}
    </delete>

    <delete id="deleteDemoStudentByStudentIds" parameterType="String">
        delete from demo_student where student_id in 
        <foreach item="studentId" collection="array" open="(" separator="," close=")">
            #{studentId}
        </foreach>
    </delete>
</mapper>