You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
exam/mapper/sys/depart/SysDepartMapper.xml

59 lines
3.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?xml version="1.0" encoding="UTF-8"?>
<!-- 定义文档类型,引用 MyBatis Mapper 3.0 的 DTD 规范,用于验证 XML 文档结构是否符合 MyBatis Mapper 标准 -->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 定义 Mapper 命名空间,关联到对应的 Java Mapper 接口,方便 MyBatis 找到对应的操作方法 -->
<mapper namespace="com.yf.exam.modules.sys.depart.mapper.SysDepartMapper">
<!-- 通用查询映射结果,将数据库查询结果映射到 Java 实体类 com.yf.exam.modules.sys.depart.entity.SysDepart -->
<resultMap id="BaseResultMap" type="com.yf.exam.modules.sys.depart.entity.SysDepart">
<!-- 映射数据库表的主键列 id 到 Java 实体类的 id 属性 -->
<id column="id" property="id" />
<!-- 映射数据库表的 dept_type 列到 Java 实体类的 deptType 属性 -->
<result column="dept_type" property="deptType" />
<!-- 映射数据库表的 parent_id 列到 Java 实体类的 parentId 属性 -->
<result column="parent_id" property="parentId" />
<!-- 映射数据库表的 dept_name 列到 Java 实体类的 deptName 属性 -->
<result column="dept_name" property="deptName" />
<!-- 映射数据库表的 dept_code 列到 Java 实体类的 deptCode 属性 -->
<result column="dept_code" property="deptCode" />
<!-- 映射数据库表的 sort 列到 Java 实体类的 sort 属性 -->
<result column="sort" property="sort" />
</resultMap>
<!-- 通用查询结果列,定义可复用的 SQL 片段,包含常用查询列,可在其他 SQL 语句中引用 -->
<sql id="Base_Column_List">
`id`,`dept_type`,`parent_id`,`dept_name`,`dept_code`,`sort`
</sql>
<!-- 树形结构查询结果映射,将结果映射到 Java DTO 类 com.yf.exam.modules.sys.depart.dto.response.SysDepartTreeDTO继承自 BaseResultMap -->
<resultMap id="TreeResultMap"
type="com.yf.exam.modules.sys.depart.dto.response.SysDepartTreeDTO"
extends="BaseResultMap">
<!-- 集合映射,将关联查询结果映射到 Java DTO 类的 children 属性 -->
<!-- column: 传递给关联查询的参数,这里传递 id 列的值 -->
<!-- select: 指定关联查询的方法,调用本 Mapper 中的 findChildren 方法 -->
<collection property="children" column="id" select="findChildren"></collection>
</resultMap>
<!-- 查询指定父部门下的子部门列表,使用 TreeResultMap 进行结果映射 -->
<select id="findChildren" resultMap="TreeResultMap">
<!-- 从 sys_depart 表中查询所有列,筛选出 parent_id 等于传入参数 id 的记录 -->
SELECT * FROM sys_depart WHERE parent_id=#{id}
</select>
<!-- 分页查询顶级部门列表,使用 TreeResultMap 进行结果映射 -->
<select id="paging" resultMap="TreeResultMap">
<!-- 从 sys_depart 表中查询所有列,筛选出 parent_id 等于 '0' 的顶级部门记录 -->
SELECT * FROM sys_depart WHERE parent_id='0'
<!-- 判断查询参数 query 是否不为空 -->
<if test="query!=null">
<!-- 判断查询参数中的 deptName 属性是否不为空且不为空字符串 -->
<if test="query.deptName!=null and query.deptName!=''">
<!-- 添加模糊查询条件,根据部门名称过滤 -->
AND dept_name LIKE CONCAT('%',#{query.deptName},'%')
</if>
</if>
</select>
</mapper>