springboot整合jsp快速搭建增删改查的学生管理系统

简介: springboot整合jsp快速搭建增删改查的学生管理系统

接:[springboot 搭建简单demo](https://blog.csdn.net/qq_44969643/article/details/106408784)

**先看最终效果图:**



![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/20200529130723586.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0OTY5NjQz,size_16,color_FFFFFF,t_70)

由于是jsp写的,所以效果不是很好(之前做过:vue-cli+Element ui+springboot的图书管理系统,比较美观,下载地址:[github](https://github.com/hnust-xijing/BookManage.git))



新建项目:

使用maven,选择webapp(jsp需要)

pom.xml


```java

<parent>

   <groupId>org.springframework.boot</groupId>

   <artifactId>spring-boot-starter-parent</artifactId>

   <version>2.0.7.RELEASE</version>

 </parent>


 <dependencies>

   <dependency>

<!-- web相关的组件-->

     <groupId>org.springframework.boot</groupId>

     <artifactId>spring-boot-starter-web</artifactId>

   </dependency>


<!--整合jsp-->

   <dependency>

     <groupId>org.springframework.boot</groupId>

     <artifactId>spring-boot-starter-tomcat</artifactId>

   </dependency>


   <dependency>

     <groupId>org.apache.tomcat.embed</groupId>

     <artifactId>tomcat-embed-jasper</artifactId>

   </dependency>

<!--JSTL-->

   <dependency>

     <groupId>jstl</groupId>

     <artifactId>jstl</artifactId>

     <version>1.2</version>

   </dependency>

 

   <dependency>

     <groupId>org.projectlombok</groupId>

     <artifactId>lombok</artifactId>

     <version>1.18.6</version>

     <scope>provided</scope>

   </dependency>

 </dependencies>

创建配置文件 application.yml

server:

 port: 8181

spring:

 mvc:

   view:

     prefix: /

     suffix: .jsp

```

**创建配置文件 application.yml**


```java

server:

 port: 8181

spring:

 mvc:

   view:

     prefix: /

     suffix: .jsp

```

**创建Handler**


```java

package com.shuang.controller;


import com.shuang.entity.Student;

import com.shuang.repository.StudentRepository;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;


@Controller

@RequestMapping("/hello")

public class HelloHandler {


   @Autowired

   private StudentRepository studentRepository;


   @GetMapping("/index")

   public ModelAndView index(){

       ModelAndView modelAndView=new ModelAndView();

       modelAndView.setViewName("index");

       modelAndView.addObject("List",studentRepository.findAll());

       return modelAndView;

   }

   @GetMapping("/deleteById/{id}")

   public String deleteById(@PathVariable("id") long id){

       studentRepository.deleteById(id);

           return "redirect:/hello/index";

   }


   @PostMapping("/save")

   public String save(Student student){

       studentRepository.saveOrUpdate(student);

       return "redirect:/hello/index";

   }

   @PostMapping("/update")

   public String update(Student student){

       studentRepository.saveOrUpdate(student);

       return "redirect:/hello/index";

   }

   @GetMapping("/findById/{id}")

   public ModelAndView findById(@PathVariable("id") long id){

      ModelAndView modelAndView=new ModelAndView();

      modelAndView.setViewName("update");

      modelAndView.addObject("student",studentRepository.findByid(id));

       return modelAndView;

   }

}

```

**JSP**

index.jsp

```java

<%--

 Created by IntelliJ IDEA.

 User: Administrator

 Date: 2020/5/29

 Time: 10:16

 To change this template use File | Settings | File Templates.

--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ page isELIgnored="false"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>

<head>

   <title>Title</title>

</head>

<body>

   <h1>学生信息</h1>

   <table>

       <tr>

           <th>学生编号</th>

           <th>学生姓名</th>

           <th>学生年龄</th>

           <th>操作</th>

       </tr>

       <c:forEach items="${List}" var="student">

           <tr>

               <td>${student.id}</td>

               <td>${student.name}</td>

               <td>${student.age}</td>

               <td>

                   <a href="/hello/findById/${student.id}">修改</a>

                   <a href="/hello/deleteById/${student.id}">删除</a>

               </td>

           </tr>

       </c:forEach>

   </table>

   <a href="/save.jsp">添加学生</a>

</body>

</html>

```

save.jsp


```java

<%--

 Created by IntelliJ IDEA.

 User: Administrator

 Date: 2020/5/29

 Time: 12:01

 To change this template use File | Settings | File Templates.

--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>

<head>

   <title>Title</title>

</head>

<body>

  <form action="/hello/save" method="post">

      ID:<input type="text" name="id"/><br/>

      name:<input type="text" name="name"/><br/>

      age:<input type="text" name="age"/><br/>

      <input type="submit" name="提交"/>

  </form>

</body>

</html>

```

update.jsp


```java

<%--

 Created by IntelliJ IDEA.

 User: Administrator

 Date: 2020/5/29

 Time: 12:05

 To change this template use File | Settings | File Templates.

--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>

<head>

   <title>Title</title>

</head>

<body>

<form action="/hello/update" method="post">

   ID:<input type="text" name="id" value="${student.id}" readonly/><br/>

   name:<input type="text" name="name" value="${student.name}"/><br/>

   age:<input type="text" name="age" value="${student.age}"/><br/>

   <input type="submit" name="提交"/>

</form>

</body>

</html>

```

**文件目录**

![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/20200529130604962.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0OTY5NjQz,size_16,color_FFFFFF,t_70)

目录
相关文章
|
14小时前
|
JavaScript Java 关系型数据库
公寓报修|公寓报修管理系统|基于springboot公寓报修管理系统设计与实现(源码+数据库+文档)
公寓报修|公寓报修管理系统|基于springboot公寓报修管理系统设计与实现(源码+数据库+文档)
9 2
|
14小时前
|
JavaScript Java 关系型数据库
旅游|基于Springboot的旅游管理系统设计与实现(源码+数据库+文档)
旅游|基于Springboot的旅游管理系统设计与实现(源码+数据库+文档)
6 0
|
14小时前
|
存储 JavaScript Java
物流|基于Springboot的物流管理系统设计与实现(源码+数据库+文档)
物流|基于Springboot的物流管理系统设计与实现(源码+数据库+文档)
7 0
|
1天前
|
监控 NoSQL Java
java云MES 系统源码Java+ springboot+ mysql 一款基于云计算技术的企业级生产管理系统
MES系统是生产企业对制造执行系统实施的重点在智能制造执行管理领域,而MES系统特点中的可伸缩、信息精确、开放、承接、安全等也传递出:MES在此管理领域中无可替代的“王者之尊”。MES制造执行系统特点集可伸缩性、精确性、开放性、承接性、经济性与安全性于一体,帮助企业解决生产中遇到的实际问题,降低运营成本,快速适应企业不断的制造执行管理需求,使得企业已有基础设施与一切可用资源实现高度集成,提升企业投资的有效性。
28 5
|
3天前
|
监控 安全 NoSQL
采用java+springboot+vue.js+uniapp开发的一整套云MES系统源码 MES制造管理系统源码
MES系统是一套具备实时管理能力,建立一个全面的、集成的、稳定的制造物流质量控制体系;对生产线、工艺、人员、品质、效率等多方位的监控、分析、改进,满足精细化、透明化、自动化、实时化、数据化、一体化管理,实现企业柔性化制造管理。
25 3
|
6天前
|
Java
学院管理系统【JSP+Servlet+JavaBean】(Java课设)
学院管理系统【JSP+Servlet+JavaBean】(Java课设)
25 3
学院管理系统【JSP+Servlet+JavaBean】(Java课设)
|
6天前
|
Java
学校人员管理系统【JSP+Servlet+JavaBean】(Java课设)
学校人员管理系统【JSP+Servlet+JavaBean】(Java课设)
13 2
|
6天前
|
Java
学校教师管理系统【JSP+Servlet+JavaBean】(Java课设)
学校教师管理系统【JSP+Servlet+JavaBean】(Java课设)
18 2
|
6天前
|
Java
个人信息管理系统【JSP+Servlet+JavaBean】(Java课设)
个人信息管理系统【JSP+Servlet+JavaBean】(Java课设)
11 0
|
6天前
|
Java 关系型数据库 MySQL
基于JSP的教师管理系统
基于JSP的教师管理系统
11 1