- 新增StudentDOMapper接口方法selectStudentCountByClassId,用于查询班级下学生数量 - 在ClassServiceImpl中注入StudentDOMapper - 删除班级时先判断班级下是否存在学生,若存在则抛出异常防止删除 - 更新StudentDOMapper.xml,添加对应的SQL查询语句selectStudentCountByClassId
71 lines
2.5 KiB
XML
71 lines
2.5 KiB
XML
<?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.yinlihupo.enlish.service.domain.mapper.StudentDOMapper">
|
|
<resultMap id="BaseResultMap" type="com.yinlihupo.enlish.service.domain.dataobject.StudentDO">
|
|
<id column="id" jdbcType="INTEGER" property="id" />
|
|
<result column="name" jdbcType="VARCHAR" property="name" />
|
|
<result column="class_id" jdbcType="INTEGER" property="classId" />
|
|
<result column="grade_id" jdbcType="INTEGER" property="gradeId" />
|
|
<result column="initial_vocabulary_size" jdbcType="INTEGER" property="initialVocabularySize" />
|
|
<result column="current_vocabulary_size" jdbcType="INTEGER" property="currentVocabularySize" />
|
|
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
|
|
<result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
|
|
</resultMap>
|
|
|
|
<select id="selectStudentDOListByClassIdAndGradeId" resultMap="BaseResultMap">
|
|
select *
|
|
from student
|
|
where 1 = 1
|
|
<if test="classId != null">
|
|
AND class_id = #{classId}
|
|
</if>
|
|
<if test="gradeId != null">
|
|
AND grade_id = #{gradeId}
|
|
</if>
|
|
<if test="name != null">
|
|
AND name like concat('%', #{name}, '%')
|
|
</if>
|
|
and is_deleted = 0
|
|
order by start_time desc
|
|
LIMIT #{startIndex}, #{pageSize}
|
|
</select>
|
|
|
|
<select id="selectStudentCount">
|
|
select count(1)
|
|
from student
|
|
</select>
|
|
|
|
<select id="selectStudentById" resultMap="BaseResultMap">
|
|
select *
|
|
from student
|
|
where id = #{id}
|
|
</select>
|
|
|
|
<select id="selectStudentDOListByIds" resultMap="BaseResultMap">
|
|
select *
|
|
from student
|
|
where id in
|
|
<foreach item="id" collection="ids" separator="," open="(" close=")" index="index">
|
|
#{id}
|
|
</foreach>
|
|
</select>
|
|
|
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
|
insert into student
|
|
(name, class_id, grade_id, is_deleted, start_time)
|
|
values (#{name}, #{classId}, #{gradeId}, 0, #{startTime})
|
|
</insert>
|
|
|
|
<update id="deleteById">
|
|
update student
|
|
set is_deleted = 1
|
|
where id = #{id}
|
|
</update>
|
|
|
|
<select id="selectStudentCountByClassId" resultType="java.lang.Integer">
|
|
select count(1)
|
|
from student
|
|
where class_id = #{classId}
|
|
and is_deleted = 0
|
|
</select>
|
|
</mapper> |