吕淼 2 weeks ago
parent fec941e6ca
commit 76a63f4128

@ -0,0 +1,75 @@
package com.ssm.controller;
import com.ssm.entity.Course;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class CourseController {
@RequestMapping("/addCourse")
public String add(Course course, Model model) {
try {
System.out.println("===== 组员吕淼-课程模块 =====");
System.out.println("接收数据:" + course);
// 基本数据验证
if (course.getCourseId() == null || course.getCourseId() <= 0) {
model.addAttribute("msg", "课程ID不能为空");
return "/addCourse.jsp";
}
if (course.getCourseName() == null || course.getCourseName().trim().length() <= 0) {
model.addAttribute("msg", "课程名称不能为空!");
return "/addCourse.jsp";
}
if (course.getCredit() == null || course.getCredit() <= 0) {
model.addAttribute("msg", "课程学分不能为空!");
return "/addCourse.jsp";
}
if (course.getTeacher() == null || course.getTeacher().trim().length() <= 0) {
model.addAttribute("msg", "课程教师不能为空!");
return "/addCourse.jsp";
}
model.addAttribute("msg", "课程信息提交成功!");
return "showCourse";
} catch (Exception e) {
System.err.println("数据处理异常:" + e.getMessage());
model.addAttribute("msg", "数据提交失败,请检查输入格式!");
return "/addCourse.jsp";
}
}
// ... existing code ...
// 新增方法:接收表单信息并响应到页面
// 新增方法:接收表单信息并响应到页面
@RequestMapping("/submitStockAccount")
public String submitCourse(Course course, Model model) {
try {
System.out.println("===== 课程提交 =====");
System.out.println("接收数据:" + course);
// 将表单信息添加到Model中传递到页面
model.addAttribute("course", course);
return "showCourse";
} catch (Exception e) {
System.err.println("数据处理异常:" + e.getMessage());
model.addAttribute("msg", "数据提交失败,请检查输入格式!");
return "/addCourse.jsp";
}
}
// ... existing code ...
// 全局异常处理 - 处理数据绑定异常
@ExceptionHandler(Exception.class)
public String handleException(Exception e, Model model) {
System.err.println("系统异常:" + e.getMessage());
model.addAttribute("msg", "系统错误:" + e.getMessage());
return "showCourse";
}
}

@ -0,0 +1,50 @@
package com.ssm.entity;
public class Course {
private Integer courseId; // 课程ID
private String courseName; // 课程名称
private Double credit; // 学分
private String teacher; // 教师
public Integer getCourseId() {
return courseId;
}
public void setCourseId(Integer courseId) {
this.courseId = courseId;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public Double getCredit() {
return credit;
}
public void setCredit(Double credit) {
this.credit = credit;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
@Override
public String toString() {
return "Course{" +
"courseId=" + courseId +
", courseName='" + courseName + '\'' +
", credit=" + credit +
", teacher='" + teacher + '\'' +
'}';
}
}

@ -0,0 +1,34 @@
<%--
Created by IntelliJ IDEA.
User: 86155
Date: 2026/5/19
Time: 11:05
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>提交成功</title>
</head>
<body>
<h3>提交成功</h3>
<table>
<tr>
<td>课程ID</td>
<td>${course.courseId}</td>
</tr>
<tr>
<td>课程名称:</td>
<td>${course.courseName}</td>
</tr>
<tr>
<td>学分:</td>
<td>${course.credit}</td>
</tr>
<tr>
<td>授课教师:</td>
<td>${course.teacher}</td>
</tr>
</table>
</body>
</html>

@ -0,0 +1,25 @@
<%--
Created by IntelliJ IDEA.
User: 86155
Date: 2026/5/19
Time: 11:05
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>课程信息</title>
</head>
<body>
<h3>课程信息</h3>
<form action="addCourse" method="post">
课程ID<input type="text" name="courseId" placeholder="请输入课程ID"><br>
课程名称:<input type="text" name="courseName" placeholder="请输入课程名称"><br>
课程学分:<input type="text" name="credit" placeholder="请输入课程学分"><br>
课程教师:<input type="text" name="teacher" placeholder="请输入课程教师"><br>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>

@ -1,13 +1,13 @@
package com.ssm.di.xml;
// 班级实体类 DI XML版
public class ClassEntity {
public class Class {
private Integer classId;
private String className;
private Integer studentCount;
// 无参构造 Spring必须
public ClassEntity() {}
public Class() {}
// setter方法用于XML setter注入
public Integer getClassId() { return classId; }

@ -17,7 +17,7 @@
<aop:aspectj-autoproxy/>
<!-- 注册Bean -->
<bean id="cls" class="com.ssm.aop.Class">
<bean id="cls" class="com.ssm.aop.ClassEntity">
<property name="classId" value="1"/>
<property name="className" value="软件工程"/>
<property name="studentCount" value="20"/>

@ -5,7 +5,7 @@
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 分工1班级Bean Setter属性注入 -->
<bean id="classInfo" class="com.ssm.di.xml.Class">
<bean id="classInfo" class="com.ssm.di.xml.ClassEntity">
<property name="classId" value="1"/>
<property name="className" value="计算机25-12B班"/>
<property name="studentCount" value="45"/>

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="class" class="com.ssm.ioc.Class">
<bean id="class" class="com.ssm.ioc.ClassEntity">
<property name="classId" value="1"/>
<property name="className" value="计算机科学与技术1班"/>
<property name="grade" value="2023级"/>

Loading…
Cancel
Save