<?xml version="1.0" encoding="UTF-8" ?>
<mapper namespace="com.fh.mapper.StudentMapper">
<!-- 条件查询-->
<sql id="studentWhere">
<where>
<!-- 查询名称-->
<if test="studentName != null and studentName != ''">
s.studentName like concat('%',#{studentName},'%')
</if>
<!-- 查询年龄-->
<if test="minage != null">
and s.age >= #{minage}
</if>
<if test="maxage != null">
and s.age <= #{maxage}
</if>
<!-- 查询出生日期-->
<if test="minDate != null">
and s.birthday >= #{minDate}
</if>
<if test="maxDate != null">
and s.birthday <= #{maxDate}
</if>
<!-- 查询体重-->
<if test="minweight != null">
and s.weight >= #{minweight}
</if>
<if test="maxweight != null">
and s.weight <= #{maxweight}
</if>
<!-- 查询班级下拉框 这是另一张表-->
<if test="gradea != null and gradea != -1">
and s.gradeId = #{gradea}
</if>
<!-- 查询复选框 爱好-->
<if test="hobby != null and hobby != ''">
and s.hobby in (${hobby})
</if>
<!-- 查询性别 单选-->
<if test="sex != null">
and s.sex = #{sex}
</if>
</where>
</sql>
<!-- 注册、登录时根据名称查询用户是否存在-->
<select id="queryUserByUserName" parameterType="java.lang.String" resultType="User">
select * from s_user where username=#{userName}
</select>
<!-- 查询总条数-->
<select id="queryCount" resultType="long">
select count(*) from s_student
<include refid="studentWhere"></include>
</select>
<!-- 查询数据-->
<select id="queryStudent" resultType="Student">
select * from s_student s left join s_grade g on s.gradeId = g.gradeId <include refid="studentWhere"></include> limit #{start},#{length}
</select>
<!-- 查询班级-->
<select id="queryGrade" resultType="Grade">
select * from s_grade
</select>
<!-- 回显-->
<select id="queryStudentById" parameterType="int" resultType="Student">
select * from s_student where id = #{id}
</select>
<!-- 新增数据-->
<select id="addStudent" parameterType="Student">
insert into s_student (studentName,age,weight,sex,hobby,birthday,fileName,gradeId) values (#{studentName},#{age},#{weight},#{sex},#{hobby},#{birthday},#{fileName},#{gradeId})
</select>
<!-- 修改数据-->
<select id="uodateStudent" parameterType="Student">
update s_student set studentName=#{studentName},age=#{age},weight=#{weight},sex=#{sex},hobby=#{hobby},weight=#{weight},birthday=#{birthday},fileName=#{fileName},gradeId=#{gradeId} where id=#{id}
</select>
<!--删除-->
<delete id="deleteStudent" parameterType="int">
delete from s_student where id = #{id}
</delete>
<delete id="pideleteStudent" parameterType="list">
delete from s_student where id in
<foreach collection="list" separator="," open="(" close=")" item="id">
#{id}
</foreach>
</delete>
</mapper>