From a63805381e66a6620a824100e80acfcf8cea9ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E5=AE=87?= <1299892569@qq.com> Date: Tue, 2 Dec 2025 17:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 38 ++++++++ .idea/.gitignore | 8 ++ .idea/encodings.xml | 7 ++ .idea/misc.xml | 15 ++++ .idea/vcs.xml | 6 ++ pom.xml | 86 +++++++++++++++++++ .../campus/controller/StudentController.java | 27 ++++++ src/main/java/com/campus/entity/Student.java | 49 +++++++++++ src/main/java/com/campus/entity/User.java | 41 +++++++++ .../java/com/campus/mapper/StudentMapper.java | 14 +++ .../java/com/campus/mapper/StudentMapper.xml | 10 +++ .../com/campus/service/StudentService.java | 23 +++++ src/main/resources/applicationContext.xml | 43 ++++++++++ src/main/resources/jdbc.properties | 4 + src/main/resources/mybatis-config.xml | 9 ++ src/main/resources/spring-mvc.xml | 27 ++++++ src/main/webapp/WEB-INF/jsp/student_list.jsp | 35 ++++++++ src/main/webapp/WEB-INF/web.xml | 30 +++++++ src/main/webapp/index.jsp | 5 ++ 19 files changed, 477 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/campus/controller/StudentController.java create mode 100644 src/main/java/com/campus/entity/Student.java create mode 100644 src/main/java/com/campus/entity/User.java create mode 100644 src/main/java/com/campus/mapper/StudentMapper.java create mode 100644 src/main/java/com/campus/mapper/StudentMapper.xml create mode 100644 src/main/java/com/campus/service/StudentService.java create mode 100644 src/main/resources/applicationContext.xml create mode 100644 src/main/resources/jdbc.properties create mode 100644 src/main/resources/mybatis-config.xml create mode 100644 src/main/resources/spring-mvc.xml create mode 100644 src/main/webapp/WEB-INF/jsp/student_list.jsp create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/index.jsp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1741622 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + {} + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..77fbb28 --- /dev/null +++ b/pom.xml @@ -0,0 +1,86 @@ + + 4.0.0 + com.campus + campus-attendance + 1.0-SNAPSHOT + war + + + 1.8 + 5.3.30 + 3.5.13 + 8.0.33 + + + + + + org.springframework + spring-webmvc + ${spring.version} + + + + + org.springframework + spring-jdbc + ${spring.version} + + + + + org.mybatis + mybatis + ${mybatis.version} + + + org.mybatis + mybatis-spring + 2.0.9 + + + + + mysql + mysql-connector-java + ${mysql.version} + + + com.alibaba + druid + 1.2.16 + + + + + com.fasterxml.jackson.core + jackson-databind + 2.13.0 + + + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + + + campus-attendance + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + \ No newline at end of file diff --git a/src/main/java/com/campus/controller/StudentController.java b/src/main/java/com/campus/controller/StudentController.java new file mode 100644 index 0000000..87373ce --- /dev/null +++ b/src/main/java/com/campus/controller/StudentController.java @@ -0,0 +1,27 @@ +package com.campus.controller; + +import com.campus.entity.Student; +import com.campus.service.StudentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +// StudentController.java +@RestController +@RequestMapping("/student") +public class StudentController { + @Autowired + private StudentService studentService; + + @GetMapping("/list") + public List list() { + return studentService.listAll(); + } + + @PostMapping("/add") + public String add(@RequestBody Student student) { + studentService.add(student); + return "success"; + } +} \ No newline at end of file diff --git a/src/main/java/com/campus/entity/Student.java b/src/main/java/com/campus/entity/Student.java new file mode 100644 index 0000000..53efcd4 --- /dev/null +++ b/src/main/java/com/campus/entity/Student.java @@ -0,0 +1,49 @@ +package com.campus.entity; + +public class Student { + private Integer id; + private String name; + private String studentId; + private String class_; + private String major; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getClass_() { + return class_; + } + + public void setClass_(String class_) { + this.class_ = class_; + } + + public String getStudentId() { + return studentId; + } + + public void setStudentId(String studentId) { + this.studentId = studentId; + } + + public String getMajor() { + return major; + } + + public void setMajor(String major) { + this.major = major; + } +} \ No newline at end of file diff --git a/src/main/java/com/campus/entity/User.java b/src/main/java/com/campus/entity/User.java new file mode 100644 index 0000000..3c4f8ae --- /dev/null +++ b/src/main/java/com/campus/entity/User.java @@ -0,0 +1,41 @@ +package com.campus.entity; + +// User.java +public class User { + private Integer id; + private String username; + private String password; + private String role; // ADMIN/TEACHER/STUDENT + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } +} \ No newline at end of file diff --git a/src/main/java/com/campus/mapper/StudentMapper.java b/src/main/java/com/campus/mapper/StudentMapper.java new file mode 100644 index 0000000..538191b --- /dev/null +++ b/src/main/java/com/campus/mapper/StudentMapper.java @@ -0,0 +1,14 @@ +package com.campus.mapper; + +import com.campus.entity.Student; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface StudentMapper { + List selectAll(); + void insert(Student student); + void update(Student student); + void delete(Integer id); +} \ No newline at end of file diff --git a/src/main/java/com/campus/mapper/StudentMapper.xml b/src/main/java/com/campus/mapper/StudentMapper.xml new file mode 100644 index 0000000..c1b7d1d --- /dev/null +++ b/src/main/java/com/campus/mapper/StudentMapper.xml @@ -0,0 +1,10 @@ + + + + + INSERT INTO student(name, student_id, class, major) + VALUES(#{name}, #{studentId}, #{class_}, #{major}) + + \ No newline at end of file diff --git a/src/main/java/com/campus/service/StudentService.java b/src/main/java/com/campus/service/StudentService.java new file mode 100644 index 0000000..8452b00 --- /dev/null +++ b/src/main/java/com/campus/service/StudentService.java @@ -0,0 +1,23 @@ +package com.campus.service; + +import com.campus.entity.Student; +import com.campus.mapper.StudentMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +// StudentService.java +@Service +public class StudentService { + @Autowired + private StudentMapper studentMapper; + + public List listAll() { + return studentMapper.selectAll(); + } + + public void add(Student student) { + studentMapper.insert(student); + } +} \ No newline at end of file diff --git a/src/main/resources/applicationContext.xml b/src/main/resources/applicationContext.xml new file mode 100644 index 0000000..faacb09 --- /dev/null +++ b/src/main/resources/applicationContext.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/jdbc.properties b/src/main/resources/jdbc.properties new file mode 100644 index 0000000..569b7be --- /dev/null +++ b/src/main/resources/jdbc.properties @@ -0,0 +1,4 @@ +jdbc.driver=com.mysql.cj.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/campus_attendance?useSSL=false&serverTimezone=UTC +jdbc.username=root +jdbc.password=123456 \ No newline at end of file diff --git a/src/main/resources/mybatis-config.xml b/src/main/resources/mybatis-config.xml new file mode 100644 index 0000000..a15707b --- /dev/null +++ b/src/main/resources/mybatis-config.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/spring-mvc.xml b/src/main/resources/spring-mvc.xml new file mode 100644 index 0000000..41de6f2 --- /dev/null +++ b/src/main/resources/spring-mvc.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/student_list.jsp b/src/main/webapp/WEB-INF/jsp/student_list.jsp new file mode 100644 index 0000000..73dc8de --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/student_list.jsp @@ -0,0 +1,35 @@ + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 学生管理 + + + + + + + + + + + +
姓名学号班级专业
+ + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..f05a1c9 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,30 @@ + + + + + + contextConfigLocation + classpath:applicationContext.xml + + + org.springframework.web.context.ContextLoaderListener + + + + + dispatcher + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + classpath:spring-mvc.xml + + 1 + + + dispatcher + / + + \ No newline at end of file diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..c38169b --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,5 @@ + + +

Hello World!

+ +