springboot实现学生管理系统

SpringBoot实现学生管理系统

一、创建springboot项目

在这里插入图片描述
点击下一步
在这里插入图片描述
点击下一步,选择要添加的依赖
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
点击下一步,再点击完成
修改pom.xml如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.6.7</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.young</groupId>
	<artifactId>springboot04</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>springboot04</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>1.8</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web-services</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>2.1.0</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.webjars</groupId>
			<artifactId>jquery</artifactId>
			<version>3.3.1</version>
		</dependency>
		<dependency>
			<groupId>org.webjars</groupId>
			<artifactId>bootstrap</artifactId>
			<version>4.0.0</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

修改resources目录下的application.yml,代码如下

spring:
  thymeleaf:
    prefix: classpath:/templates/
    suffix: .html
  mvc:
    view:
      static-path-pattern: /static/**
  datasource:
    url: jdbc:mysql://localhost:3306/springboot?useSSL=false&serverTimezone=UTC
    username: root
    password: 3fa4d180
    driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
  mapper-locations: classpath:mapper/*.xml

我们在我们创建的目录下,创建pojo软件包,在该包下创建Student.java

public class Student {
    private Integer id;
    private String name;
    private String grade;
    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 getGrade() {
        return grade;
    }
    public void setGrade(String grade) {
        this.grade = grade;
    }
    public String getMajor() {
        return major;
    }
    public void setMajor(String major) {
        this.major = major;
    }
    @Override
    public String toString(){
        return "Student{id="+id+",name="+name+
                ",grade="+grade+",major="+major+
                "}";
    }
}

我们在创建一个mapper软件包,创建StudentMapper接口

@Mapper
public interface StudentMapper {
    List<Student>listStudent();
    List<Student>queryStudentByValue(String value);
    int saveStudent(Student student);
    int deleteStudent(Integer id);
    int updateStudent(Student student);
}

创建一个service软件包,创建StudentService

@Service
public class StudentService {
    @Autowired
    private StudentMapper studentMapper;
    public List<Student>listStudent(){
        return studentMapper.listStudent();
    }
    public List<Student>queryStudentByValue(String value){
        return studentMapper.queryStudentByValue(value);
    }
    public int saveStudent(Student student){
        return studentMapper.saveStudent(student);
    }
    public int deleteStudent(Integer id){
        return studentMapper.deleteStudent(id);
    }
    public int updateStudent(Student student){
        return studentMapper.updateStudent(student);
    }
}

创建一个controller软件包,创建StudentController

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping("/listStudent")
    public ModelAndView listStudent(){
        List<Student>studentList=studentService.listStudent();
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("studentList",studentList);
        modelAndView.setViewName("/listStudent");
        return modelAndView;
    }
    @RequestMapping("/queryStudentByValue")
    public ModelAndView queryStudentByValue(String value){
        List<Student>studentList=studentService.queryStudentByValue(value);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("studentList",studentList);
        modelAndView.setViewName("/listStudent");
        return modelAndView;
    }
    @RequestMapping("/saveStudent")
    public ModelAndView saveStudent(Student student){
        ModelAndView modelAndView=new ModelAndView();
        studentService.saveStudent(student);
        modelAndView.setViewName("forward:/student/listStudent");
        return modelAndView;
    }
    @RequestMapping("/updateStudent")
    public ModelAndView updateStudent(Student student){
        ModelAndView modelAndView=new ModelAndView();
        studentService.updateStudent(student);
        modelAndView.setViewName("forward:/student/listStudent");
        return modelAndView;
    }
    @RequestMapping("/deleteStudent")
    public ModelAndView deleteStudent(Integer id){
        ModelAndView modelAndView=new ModelAndView();
        studentService.deleteStudent(id);
        modelAndView.setViewName("forward:/student/listStudent");
        return modelAndView;
    }
}

在resources目录下,创建mapper目录,在该目录下,放入我们的StudentMapper.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.young.springboot04.mapper.StudentMapper">
    <select id="listStudent" resultType="com.young.springboot04.pojo.Student">
        select * from student
    </select>
    <select id="queryStudentByValue" parameterType="string" resultType="com.young.springboot04.pojo.Student">
        select * from student
        where id like '%${value}%' or name like '%${value}%' or grade like '%${value}%'
        or major like '%${value}%'
    </select>
    <insert id="saveStudent" parameterType="com.young.springboot04.pojo.Student">
        insert into student
        values(#{id},#{name},#{grade},#{major})
    </insert>
    <delete id="deleteStudent" parameterType="int">
        delete from student
        where id=#{id}
    </delete>
    <update id="updateStudent" parameterType="com.young.springboot04.pojo.Student">
        update student
        set name=#{name},grade=#{grade},major=#{major}
        where id=#{id}
    </update>
</mapper>

在我们的static目录下, 放入我们需要的css目录,我这里用的是pio框架的css目录
接着我们在templates目录下创建listStudent.html,用于显示内容

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>学生列表</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
  <link rel="stylesheet" href="../static/css/pico.min.css" th:href="@{/css/pico.min.css}">
  <style>
    #bodyLeft{
      position:relative;
      width:66%;
      float:left;
    }
    #bodyRight{
      position:relative;
      width:29%;
      float:right;
    }
    #editForm{
      position:absolute;
      margin-top:5%;
      margin-left:35%;
      width:30%;
      background-color:white;
      z-index:1;
      border:1px solid black;
      modal:true;
      border-radius:5%;
    }
  </style>
  <script type="text/javascript" th:inlne="javascript">
    function editStudent(student){
      var id=student.id;
      var name=student.name
      var grade=student.grade
      var major=student.major
      var editForm=document.getElementById("editForm");
      editForm.style.display="block";
      editForm.innerHTML=
      "<form action='http://localhost:8080/student/updateStudent' method='post' style='width:80%;margin-left:10%;margin-top:10%;'>"+
      "<label for='name'>姓名<input type='text' id='name' value="+name+" name='name'></label>"+
      "<label for='grade'>年级<input type='text' id='grade' value="+grade+" name='grade'></label>"+
      "<label for='major'>专业<input type='text' id='major' value="+major+" name='major'></label>"+
      "<label for='id' style='display:none;'>学号<input type='text' id='id' value="+id+" name='id' hidden></label>"+
      "<input type='submit' value='修改'>"+
      "<button style='outline'><a th:href='@{/student/listStudent}' style='color:white;'>取消</a></button>"+
      "</form>";
    }
  </script>
</head>
<body>
  <!--隐藏的表单弹窗-->
<div id="editForm" style="display:none"></div>
<div class="container" style="margin-top:5%;">
  <div id="bodyLeft">
    <table role="grid">
      <tr>
        <th scope="col">学号</th>
        <th scope="col">姓名</th>
        <th scope="col">年级</th>
        <th scope="col">专业</th>
        <th scope="col">编辑</th>
        <th scope="col">删除</th>
      </tr>
      <div th:each="student:${studentList}">
        <tr>
          <td scope="row" th:text="${student.id}">学号</td>
          <td th:text="${student.name}">姓名</td>
          <td th:text="${student.grade}">年级</td>
          <td th:text="${student.major}">专业</td>
          <td><a th:onclick="editStudent([[${student}]])" href="#">编辑</a></td>
          <td><a th:href="@{/student/deleteStudent(id=${student.id})}">删除</a></td>
        </tr>
      </div>
    </table>
  </div>
  <div id="bodyRight">
    <form th:action="@{/student/saveStudent}" method="post">
      <label for="name">
        姓名<input type="text" id="name" name="name" placeholder="请输入姓名">
      </label>
      <label for="grade">
        年级<input type="text" id="grade" name="grade" placeholder="请输入年级">
      </label>
      <label for="major">
        专业<input type="text" id="major" name="major" placeholder="请输入专业">
      </label>
      <input type="submit" value="修改">
    </form>
  </div>
</div>
</body>
</html>

运行效果如下:
在这里插入图片描述
点击编辑
在这里插入图片描述

  • 11
    点赞
  • 112
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
学生档案管理系统使用Spring Boot框架开发,可以实现对学生个人信息、课程成绩、考勤记录等信息的管理和查询。系统采用前后端分离的架构,前端使用HTML、CSS和JavaScript进行开发,后端使用Spring Boot框架搭建RESTful API,以实现与前端的数据交互。 系统中包含学生信息管理模块,可以对学生的基本信息进行增删改查操作,包括姓名、学号、性别、年龄等。另外,还包含课程成绩管理模块,可以录入和查询学生的各科成绩情况,并提供统计分析功能。同时,系统还具有考勤管理功能,可以记录学生的出勤情况,以及对缺勤、迟到等情况进行管理和处理。 在系统开发过程中,可以利用Spring Boot提供的自动配置、快速开发等特性,简化开发流程,提高开发效率。另外,Spring Boot还支持集成各种常用的框架和组件,如Spring Data JPA用于数据库操作、Spring Security用于权限控制等,使得系统的功能更加完善和安全。 在部署时,可以将系统打包成可执行的JAR文件,通过命令行运行即可启动整个应用,也可以结合Docker等容器技术进行部署和管理。同时,Spring Boot还提供了丰富的监控和管理功能,通过Actuator模块可以方便地查看应用的运行状态、性能指标等信息。 总之,学生档案管理系统使用Spring Boot框架可以提供稳定、高效的管理和查询功能,为学校和教育机构提供了便利和支持。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值