springboot实现学生管理系统

本文实例为大家分享了SpringBoot实现学生管理系统,供大家参考,具体内容如下

一、创建springboot项目

springboot实现学生管理系统_第1张图片

点击下一步

springboot实现学生管理系统_第2张图片

点击下一步,选择要添加的依赖

springboot实现学生管理系统_第3张图片

springboot实现学生管理系统_第4张图片

springboot实现学生管理系统_第5张图片

点击下一步,再点击完成

修改pom.xml如下



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.6.7
         
    
    com.young
    springboot04
    0.0.1-SNAPSHOT
    springboot04
    Demo project for Spring Boot
    
        1.8
    
    
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-web-services
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.0
        
        
            mysql
            mysql-connector-java
            runtime
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.webjars
            jquery
            3.3.1
        
        
            org.webjars
            bootstrap
            4.0.0
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

修改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 {
    ListlistStudent();
    ListqueryStudentByValue(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 ListlistStudent(){
        return studentMapper.listStudent();
    }
    public ListqueryStudentByValue(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(){
        ListstudentList=studentService.listStudent();
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("studentList",studentList);
        modelAndView.setViewName("/listStudent");
        return modelAndView;
    }
    @RequestMapping("/queryStudentByValue")
    public ModelAndView queryStudentByValue(String value){
        ListstudentList=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配置




    
    
    
        insert into student
        values(#{id},#{name},#{grade},#{major})
    
    
        delete from student
        where id=#{id}
    
    
        update student
        set name=#{name},grade=#{grade},major=#{major}
        where id=#{id}
    

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




    
    学生列表
    
  
  
  


  

 
                                                                     
       
                                                                             
学号姓名年级专业编辑删除
学号姓名年级专业编辑删除
 
 
   
                           
 

运行效果如下:

springboot实现学生管理系统_第6张图片

点击编辑

springboot实现学生管理系统_第7张图片

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(springboot实现学生管理系统)