<?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.example.teacher_admin_system.mappers.EvaluationMapper"> <resultMap id="EvaluationResult" type="com.example.teacher_admin_system.pojo.Evaluation"> <!--<result column="id" property="id"></result> <result column="teacher_id" property="teacher_id"></result> <result column="evaluator_name" property="evaluator_name"></result> <result column="content" property="content"></result> <result column="score" property="score"></result> <result column="time" property="time"></result>--> <result column="name" property="name"></result> <result column="avg(score)" property="avg"></result> </resultMap> <select id="findAll" resultMap="EvaluationResult"> select name,avg(score) from evaluation join teacher on evaluation.teacher_id=teacher.id group BY teacher_id </select> <select id="findById" resultMap="EvaluationResult"> select teacher.name,avg(score) from evaluation join teacher on evaluation.teacher_id=teacher.id group BY teacher_id HAVING teacher_id = #{id};</select> <select id="findByName" resultMap="EvaluationResult"> select teacher.name,avg(score) from evaluation join teacher on evaluation.teacher_id=teacher.id join department on department.id=teacher.department_id where department.name='???????' group BY teacher_id; </select> </mapper>
时间: 2024-02-23 09:57:33 浏览: 74
mybatis-3-config/mapper.dtd 解决mybatis头文件报错
这是一个 MyBatis 的 Mapper 文件,它定义了一个名为 "com.example.teacher_admin_system.mappers.EvaluationMapper" 的命名空间,其中包含三个 SQL 查询语句。第一个查询语句是 "findAll",它使用了一个 "EvaluationResult" 的结果映射,从 "evaluation" 和 "teacher" 两个表中联合查询并计算平均分数,最终以教师名字和平均分数作为结果返回。第二个查询语句是 "findById",它也使用了 "EvaluationResult" 的结果映射,从 "evaluation" 和 "teacher" 两个表中联合查询并计算指定教师的平均分数,最终以教师名字和平均分数作为结果返回。第三个查询语句是 "findByName",它也使用了 "EvaluationResult" 的结果映射,从 "evaluation"、"teacher" 和 "department" 三个表中联合查询并计算指定部门中所有教师的平均分数,最终以教师名字和平均分数作为结果返回。需要注意的是,该文件中的部分内容被省略或用 "???" 替代,需要根据实际情况进行填写。
阅读全文