ClassRoom DTD

DTD
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT classroom (grade,claName,students)>
<!ATTLIST classroom id ID #REQUIRED>
<!ELEMENT grade (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT students (student+)>
<!ELEMENT student (id,stuName,age)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT stuName (#PCDATA)>
<!ELEMENT age (#PCDATA)>


XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE classroom SYSTEM "classroom.dtd">
<classroom id="p1">
	<grade>2012</grade>
	<claName>计算机科学与技术</claName>
	<students>
		<student>
			<id>01</id>
			<stuName>admin</stuName>
			<age>10</age>
		</student>
		<student>
			<id>02</id>
			<stuName>sa</stuName>
			<age>10</age>
		</student>
	</students>
</classroom>


 

<?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.hx.sscs.mapper.OfficeMapper"> <!-- 1. 定义联查结果映射VO(办公室+教师) --> <resultMap id="OfficeTeacherVO" type="com.hx.sscs.vo.OfficeTeacherVO"> <id column="course_id" property="courseId" /> <result column="task" property="task" /> <result column="classroom" property="classroom" /> <result column="class_time" property="classTime" /> <result column="teacher_id" property="teacherId" /> <result column="teacher_name" property="teacherName" /> <result column="department" property="department" /> </resultMap> <!-- 2. 双表联查:根据教师ID查询办公室任务及教师信息 --> <select id="selectOfficeByTeacherId" parameterType="java.lang.Integer" resultMap="OfficeTeacherVO"> SELECT o.course_id, o.task, o.classroom, o.class_time, t.teacher_id, t.teacher_name, t.department FROM office o INNER JOIN teachers t ON o.teacher_id = t.teacher_id WHERE o.logical_delete = 0 AND t.logical_delete = 0 AND o.teacher_id = #{teacherId} </select> <!-- 2. 双表联查:根据教师教室查询办公室任务及教师信息 --> <select id="selectOfficeByName" parameterType="java.lang.String" resultMap="OfficeTeacherVO"> SELECT o.course_id, o.task, o.classroom, o.class_time, t.teacher_id, t.teacher_name, t.department FROM office o INNER JOIN teachers t ON o.teacher_id = t.teacher_id WHERE o.logical_delete = 0 AND t.logical_delete = 0 AND t.teacher_name LIKE CONCAT('%', #{TeacherName}, '%') </select> <!-- 3. 扩展:查询所有办公室任务及对应教师信息(不带条件) --> <select id="selectAllOfficeWithTeacher" resultMap="OfficeTeacherVO"> SELECT o.course_id, o.task, o.classroom, o.class_time, t.teacher_id, t.teacher_name, t.department FROM office o INNER JOIN teachers t ON o.teacher_id = t.teacher_id WHERE o.logical_delete = 0 AND t.logical_delete = 0 </select> </mapper> package com.hx.sscs.mapper;package com.hx.sscs.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.hx.sscs.entity.Office; import com.hx.sscs.entity.TaskList; import com.hx.sscs.entity.Teachers; import com.hx.sscs.mapper.OfficeMapper; import com.hx.sscs.service.OfficeService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.hx.sscs.vo.OfficeTeacherVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; /** * <p> * 服务实现类 * </p> * * @author testjava * @since 2025-06-05 */ @Service public class OfficeServiceImpl extends ServiceImpl<OfficeMapper, Office> implements OfficeService { @Autowired private OfficeMapper officeMapper; @Override public List<Office> searchClass(String taskName) { QueryWrapper<Office> queryWrapper = new QueryWrapper<>(); queryWrapper.like("task", taskName);//模糊查询姓名 return baseMapper.selectList(queryWrapper); } @Override public Office taskroom(String classroom) { QueryWrapper<Office> queryWrapper=new QueryWrapper<>(); queryWrapper.eq("classroom",classroom); return baseMapper.selectOne(queryWrapper); } @Override public List<OfficeTeacherVO> searchTeacher(String teacherName) {//根据姓名查询老师的教职工号,根据教职工号查询教室 List<OfficeTeacherVO> list=officeMapper.selectOfficeByName(teacherName); return list; } } package com.hx.sscs.controller; import com.hx.sscs.commonutils.R; import com.hx.sscs.entity.Office; import com.hx.sscs.entity.TaskList; import com.hx.sscs.entity.Teachers; import com.hx.sscs.handler.EduException; import com.hx.sscs.service.OfficeService; import com.hx.sscs.service.TaskListService; import com.hx.sscs.service.TeachersService; import com.hx.sscs.vo.OfficeTeacherVO; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; /** * <p> * 前端控制器 * </p> * * @author testjava * @since 2025-06-05 */ @RestController @RequestMapping("/sscs/office") public class OfficeController { //根据任务查询教室//模糊查询 @Resource private OfficeService officeService; @Resource private TeachersService teachersService; @ApiOperation(value = "模糊查询") @PostMapping("searchClass") public R searchClass( @ApiParam(name = "taskName",value = "任务名",required = true) @RequestParam String taskName ){ try{ //调用模糊查询方法 List<Office> offices=new ArrayList<>();//建立集合装填返回数据 offices=officeService.searchClass(taskName); //找到taskList的子节点,若子节点有自己的子节点则继续找出子节点; if (offices == null) { return R.error().code(60001).message("未查询到任务: " + taskName); } System.out.println(offices); return R.ok().data("tasks", offices).message("查看成功"); }catch (EduException e) { return R.error().code(e.getCode()).message(e.getMsg()); } catch (Exception e){ System.out.println(e.getMessage()); return R.error().code(60002).message("查看失败:"+e.getMessage()); } } //根据教室查询信息 @ApiOperation(value = "教室查询") @PostMapping("Class") public R Class( @ApiParam(name = "classroom",value = "教室号",required = true) @RequestParam String classroom){ try{ Office office=officeService.taskroom(classroom); System.out.println(office); return R.ok().data("office",office).message("登录成功"); }catch (EduException e) { return R.error().code(e.getCode()).message(e.getMsg()); } catch (Exception e){ System.out.println(e.getMessage()); return R.error().code(200055).message("登录失败:"+e.getMessage()); } } //根据老师查询教室 @ApiOperation(value = "任课老师查询") @PostMapping("ClassTeacher") private R ClassTeacher( @ApiParam(name = "TeacherName",value = "教师名",required = true) @RequestParam String TeacherName ){ //根据老师姓名查询id,得到多表联查的关于该id的数据//改为直接多表联查姓名 try{ List<OfficeTeacherVO> teachers=officeService.searchTeacher(TeacherName); System.out.println(teachers); return R.ok().data("OfficeTeacherVO",teachers).message("多表查询老师姓名"); }catch (EduException e) { return R.error().code(e.getCode()).message(e.getMsg()); } catch (Exception e){ System.out.println(e.getMessage()); return R.error().code(200055).message("多表查询老师姓名失败:"+e.getMessage()); } //教师号查询id //id查询Off } //根据教室查询老师 } package com.hx.sscs; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication @EnableSwagger2 @ComponentScan(basePackages = {"com.hx"}) @MapperScan("com.hx.sscs.mapper") public class Boot3Application { public static void main(String[] args) { SpringApplication.run(Boot3Application.class,args); } } package com.hx.sscs.vo; import lombok.Data; import java.io.Serializable; /** * 办公室表与教师表联查结果VO */ @Data public class OfficeTeacherVO implements Serializable { // 办公室表字段 private Integer courseId; private String task; private String classroom; private String classTime; // 教师表字段 private Integer teacherId; private String teacherName; private String department; // getter 和 setter 方法 public Integer getCourseId() { return courseId; } public void setCourseId(Integer courseId) { this.courseId = courseId; } public String getTask() { return task; } public void setTask(String task) { this.task = task; } public String getClassroom() { return classroom; } public void setClassroom(String classroom) { this.classroom = classroom; } public String getClassTime() { return classTime; } public void setClassTime(String classTime) { this.classTime = classTime; } public Integer getTeacherId() { return teacherId; } public void setTeacherId(Integer teacherId) { this.teacherId = teacherId; } public String getTeacherName() { return teacherName; } public void setTeacherName(String teacherName) { this.teacherName = teacherName; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } @Override public String toString() { return "OfficeTeacherVO{" + "courseId=" + courseId + ", task='" + task + '\'' + ", classroom='" + classroom + '\'' + ", classTime='" + classTime + '\'' + ", teacherId=" + teacherId + ", teacherName='" + teacherName + '\'' + ", department='" + department + '\'' + '}'; } } Invalid bound statement (not found): com.hx.sscs.mapper.OfficeMapper.selectOfficeByName import com.hx.sscs.entity.Office; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.hx.sscs.vo.OfficeTeacherVO; import org.apache.ibatis.annotations.Mapper; import java.util.List; /** * <p> * Mapper 接口 * </p> * * @author testjava * @since 2025-06-05 */ @Mapper public interface OfficeMapper extends BaseMapper<Office> { /** * 根据教师ID联查办公室任务及教师信息 */ List<OfficeTeacherVO> selectOfficeByTeacherId(Integer teacherId); List<OfficeTeacherVO> selectOfficeByName(String TeacherName); /** * 查询所有办公室任务及对应教师信息 */ List<OfficeTeacherVO> selectAllOfficeWithTeacher(); } package com.hx.sscs.service; import com.hx.sscs.entity.Office; import com.baomidou.mybatisplus.extension.service.IService; import com.hx.sscs.entity.TaskList; import com.hx.sscs.vo.OfficeTeacherVO; import java.io.Serializable; import java.util.List; /** * <p> * 服务类 * </p> * * @author testjava * @since 2025-06-05 */ public interface OfficeService extends IService<Office> { List<Office> searchClass(String taskName);//模糊查询 Office taskroom(String classroom); List<OfficeTeacherVO> searchTeacher(String teacherName);//教师名查询 }
06-27
# 基于Spring Boot和MyBatis的课程管理系统实现(DAO版) ## 一、项目结构 ``` src/main/java/com/example/course/ ├── controller/ # 控制器层 ├── dao/ # 数据访问层(DAO) ├── entity/ # 实体类 ├── service/ # 服务接口层 └── service/impl/ # 服务实现层 ``` ## 二、核心代码实现 ### 1. 主启动类 (CourseApplication.java) ```java package com.example.course; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class CourseApplication { public static void main(String[] args) { SpringApplication.run(CourseApplication.class, args); } } ``` ### 2. 实体类 (Course.java) ```java package com.example.course.entity; import java.util.Date; public class Course { private Integer id; private String courseName; private String teacher; private Double credit; private String classroom; private Date startTime; private Date endTime; private Date createTime; private Date updateTime; // 构造方法 public Course() {} public Course(String courseName, String teacher, Double credit, String classroom, Date startTime, Date endTime) { this.courseName = courseName; this.teacher = teacher; this.credit = credit; this.classroom = classroom; this.startTime = startTime; this.endTime = endTime; } // Getter和Setter方法 public Integer getId() { return id; } // 其他getter和setter... } ``` ### 3. DAO接口 (CourseDao.java) ```java package com.example.course.dao; import com.example.course.entity.Course; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.util.List; @Repository public interface CourseDao { // 新增课程 int insert(Course course); // 根据ID查询课程 Course selectById(Integer id); // 查询所有课程 List<Course> selectAll(); // 更新课程信息 int update(Course course); // 删除课程 int deleteById(Integer id); // 分页查询 List<Course> selectByPage(@Param("offset") int offset, @Param("pageSize") int pageSize); // 查询总数 int count(); } ``` ### 4. Service接口 (CourseService.java) ```java package com.example.course.service; import com.example.course.entity.Course; import java.util.List; public interface CourseService { // 新增课程 int addCourse(Course course); // 根据ID查询课程 Course getCourseById(Integer id); // 查询所有课程 List<Course> getAllCourses(); // 更新课程 int updateCourse(Course course); // 删除课程 int deleteCourse(Integer id); // 分页查询 List<Course> getCoursesByPage(int pageNum, int pageSize); } ``` ### 5. Service实现类 (CourseServiceImpl.java) ```java package com.example.course.service.impl; import com.example.course.dao.CourseDao; import com.example.course.entity.Course; import com.example.course.service.CourseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class CourseServiceImpl implements CourseService { @Autowired private CourseDao courseDao; @Override public int addCourse(Course course) { return courseDao.insert(course); } @Override public Course getCourseById(Integer id) { return courseDao.selectById(id); } @Override public List<Course> getAllCourses() { return courseDao.selectAll(); } @Override public int updateCourse(Course course) { return courseDao.update(course); } @Override public int deleteCourse(Integer id) { return courseDao.deleteById(id); } @Override public List<Course> getCoursesByPage(int pageNum, int pageSize) { int offset = (pageNum - 1) * pageSize; return courseDao.selectByPage(offset, pageSize); } } ``` ### 6. 控制器 (CourseController.java) ```java package com.example.course.controller; import com.example.course.entity.Course; import com.example.course.service.CourseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/api/courses") public class CourseController { @Autowired private CourseService courseService; @PostMapping public int addCourse(@RequestBody Course course) { return courseService.addCourse(course); } @GetMapping("/{id}") public Course getCourseById(@PathVariable Integer id) { return courseService.getCourseById(id); } @GetMapping public List<Course> getAllCourses() { return courseService.getAllCourses(); } @PutMapping public int updateCourse(@RequestBody Course course) { return courseService.updateCourse(course); } @DeleteMapping("/{id}") public int deleteCourse(@PathVariable Integer id) { return courseService.deleteCourse(id); } @GetMapping("/page") public List<Course> getCoursesByPage( @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) { return courseService.getCoursesByPage(pageNum, pageSize); } } ``` ### 7. MyBatis映射文件 (CourseDao.xml) ```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.example.course.dao.CourseDao"> <resultMap id="BaseResultMap" type="com.example.course.entity.Course"> <id column="id" property="id" jdbcType="INTEGER"/> <result column="course_name" property="courseName" jdbcType="VARCHAR"/> <result column="teacher" property="teacher" jdbcType="VARCHAR"/> <result column="credit" property="credit" jdbcType="DECIMAL"/> <result column="classroom" property="classroom" jdbcType="VARCHAR"/> <result column="start_time" property="startTime" jdbcType="DATE"/> <result column="end_time" property="endTime" jdbcType="DATE"/> <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/> </resultMap> <insert id="insert" parameterType="com.example.course.entity.Course" useGeneratedKeys="true" keyProperty="id"> INSERT INTO course(course_name, teacher, credit, classroom, start_time, end_time) VALUES(#{courseName}, #{teacher}, #{credit}, #{classroom}, #{startTime}, #{endTime}) </insert> <select id="selectById" resultMap="BaseResultMap"> SELECT * FROM course WHERE id = #{id} </select> <select id="selectAll" resultMap="BaseResultMap"> SELECT * FROM course </select> <update id="update" parameterType="com.example.course.entity.Course"> UPDATE course SET course_name = #{courseName}, teacher = #{teacher}, credit = #{credit}, classroom = #{classroom}, start_time = #{startTime}, end_time = #{endTime} WHERE id = #{id} </update> <delete id="deleteById"> DELETE FROM course WHERE id = #{id} </delete> <select id="selectByPage" resultMap="BaseResultMap"> SELECT * FROM course LIMIT #{offset}, #{pageSize} </select> <select id="count" resultType="int"> SELECT COUNT(*) FROM course </select> </mapper> ``` 2025-06-17T17:23:36.607+08:00 ERROR 50008 --- [demo] [ main] o.s.b.d.LoggingFailureAnalysisReporter : 为什么 根据错误日志,您的问题是由于 Spring 无法找到 CourseDao 的 bean 导致的。以下是详细分析和解决方案:
06-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值