基于springboot和vue的学生管理系统17(含源码+sql+视频导入教程+文档)

本文详细介绍了基于SpringBoot和Vue构建的学生管理系统,包括管理员、教师和学生角色的权限管理,后端技术采用Spring和Mybatis,前端使用Vue进行前后端分离。此外,还涵盖了数据库MySQL的选择和配置,以及关键代码片段和文件上传功能的实现。
摘要由CSDN通过智能技术生成

👉文末查看项目功能视频演示+获取源码+sql脚本+视频导入教程视频

1 、功能描述

  基于springboot和vue的学生管理系统17拥有三种角色:管理员、教师、学生。管理员可以自行设置多种角色多种菜单权限。

管理员:学生管理、老师、课程管理、班级管理、统计分析

教师:打分

学生:选课

图片1

1.1 背景描述

  

2、项目技术

后端框架:springboot、Mybatis

前端技术:VUE(前后端分离)

2.1 springboot

  Spring Boot是由Pivotal团队提供的基于Spring的框架,该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。Spring Boot集成了绝大部分目前流行的开发框架,就像Maven集成了所有的JAR包一样,Spring Boot集成了几乎所有的框架,使得开发者能快速搭建Spring项目。

2.2 mysql

  MySQL是一款Relational Database Management System,直译过来的意思就是关系型数据库管理系统,MySQL有着它独特的特点,这些特点使他成为目前最流行的RDBMS之一,MySQL想比与其他数据库如ORACLE、DB2等,它属于一款体积小、速度快的数据库,重点是它符合本次毕业设计的真实租赁环境,拥有成本低,开发源码这些特点,这也是选择它的主要原因。

3、开发环境

  • JAVA版本:JDK1.8(最佳)
  • IDE类型:IDEA、Eclipse都可运行
  • 数据库类型:MySql(5.7、8.x版本都可)
  • tomcat版本:无需
  • maven版本:无限制
  • 硬件环境:Windows

4、功能截图+视频演示+文档目录

4.1 登录

登录

4.2 管理员模块

管理员-学生管理

管理员-权限管理

管理员-统计分析

管理员-课程管理

管理员-学院管理

管理员-专业管理

管理员-班级管理

4.3 学生模块

学生-查看成绩

学生-选课

4.4教师模块

教师-课程管理

教师-录入成绩

4.45文档目录

文档目录

4.6 ER图

ER图

5 、核心代码实现

5.1 配置代码

server:
  port: 8089
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/boot_shiro_vue_stu?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
    username: root
    password: root
    type: com.alibaba.druid.pool.DruidDataSource
    filters: stat
    maxActive: 20
    initialSize: 1
    maxWait: 60000
    minIdle: 1
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: select 'x'
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    maxOpenPreparedStatements: 20
  devtools:
    restart:
      enabled: true


#mybatis 配置
mybatis:
  mapper-locations: classpath:com/alan/mapper/xml/*.xml
  type-aliases-package: com.alan.pojo
mybatis-plus:
  configuration:
    log-impl=org:
      apache:
        ibatis:
          logging:
            stdout:
              StdOutImpl:

5.2 其它核心代码

package com.alan.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.alan.ftp.UploadUtil;
import com.alan.pojo.User;
import com.alan.service.UserService;
import com.alan.utils.EnumCode;
import com.alan.utils.ExcelUtil;
import com.alan.utils.ResultUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;


@RestController
@RequestMapping(value = "user")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    Map<String, String> uploadImg;

    /**
     * 上传用户头像
     */
    @ResponseBody
    @RequestMapping(value = "/uploadHander", method = RequestMethod.POST)
    public String uploadLogo(HttpServletRequest request) {
        uploadImg = new HashMap<String, String>();
        uploadImg = UploadUtil.uploadImage(request, "vue_shiro_photo/userImg");
        return uploadImg.get("pic");
    }

    @RequestMapping("/upload")
    @ResponseBody
    public String handleFileUpload(MultipartFile file) {
        if (!file.isEmpty()) {
            try {
                /*
                 * 这段代码执行完毕之后,图片上传到了工程的跟路径; 大家自己扩散下思维,如果我们想把图片上传到
                 * d:/files大家是否能实现呢? 等等;
                 * 这里只是简单一个例子,请自行参考,融入到实际中可能需要大家自己做一些思考,比如: 1、文件路径; 2、文件名;
                 * 3、文件格式; 4、文件大小的限制;
                 */
                BufferedOutputStream out = new BufferedOutputStream(
                        new FileOutputStream(new File(
                                file.getOriginalFilename())));
                System.out.println(file.getName());
                out.write(file.getBytes());
                out.flush();
                out.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return "上传失败," + e.getMessage();
            } catch (IOException e) {
                e.printStackTrace();
                return "上传失败," + e.getMessage();
            }

            return "上传成功";

        } else {
            return "上传失败,因为文件是空的.";
        }
    }

    /**
     * @desc: 查询用户
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Object findUserByPage(Integer startPage,Integer pageSize,User user) {
        Page<User> page = new Page<User>(startPage,pageSize);
        List<User> list = userService.findUserByPage(page,user);
        return ResultUtil.result(EnumCode.OK.getValue(), "请求成功", list, page.getTotal());
    }

    /**
     * @desc: 新增用户
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Object addUser(@Valid User userVo, BindingResult bindingResult) {
        return userService.addUser(userVo);
    }

    /**
     * @desc: 批量删除用户
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public Object delUsers(User user) {
        String[] ids = user.getIds();
        if (null == ids || ids.length == 0) {
            return ResultUtil.result(EnumCode.BAD_REQUEST.getValue(), EnumCode.BAD_REQUEST.getText());
        }
        return userService.delUsers(ids);
    }

    /**
     * 修改用户状态
     */
    @RequestMapping(value = "/status", method = RequestMethod.POST)
    public Object editUserStatus(User dto) {
        if (StringUtils.isEmpty(dto.getId()) || null == dto.getEnable()) {
            return ResultUtil.result(EnumCode.BAD_REQUEST.getValue(), EnumCode.BAD_REQUEST.getText());
        }
        return userService.editUserStatus(dto);
    }

    /**
     * 用户修改用户个人信息
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Object editUserInfo(User vo) {
        return userService.editUserInfo(vo);
    }


    /**
     * 导出报表,这里get和post请求复用了该方法,仅仅是为了测试
     *
     * @return
     */
    @RequestMapping(value = "/export")
    @ResponseBody
    public void export(@RequestBody(required = false) User user,String username,HttpServletResponse response) throws Exception {
        if (user ==null && !StringUtils.isEmpty(username)){
            //GET 请求的参数
            user = new User();
            user.setUsername(username);
        }
        //获取数据
        List<User> list = userService.findAllUser(user);

        //excel标题
        String[] title = {"姓名", "邮箱", "创建时间", "最近登录时间","角色","是否可用"};

        //excel文件名
        String fileName = System.currentTimeMillis() + ".xls";

        //sheet名
        String sheetName = "用户信息";

        //没有数据就传入null吧,Excel工具类有对null判断
        String [][] content = null;

        if (list != null && list.size() > 0){
            content = new String[list.size()][title.length];
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            for (int i = 0; i < list.size(); i++) {
                content[i] = new String[title.length];
                User obj = list.get(i);
                content[i][0] = obj.getUsername();
                content[i][1] = obj.getEmail();
                content[i][2] = obj.getCreateTime() == null ? "" : sdf.format(obj.getCreateTime());
                content[i][3] = obj.getLastLoginTime() == null ? "": sdf.format(obj.getLastLoginTime());
                content[i][4] = obj.getRoleName();
                content[i][5] = obj.getEnable()==1 ? "是" : "否";
            }
        }

        //创建HSSFWorkbook
        HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName, title, content);

        //响应到客户端
        try {
//            fileName = new String(fileName.getBytes(), "UTF-8");
//            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 批量导入用户
     *
     */
    @RequestMapping(value = "/import")
    @ResponseBody
    public Object ExcelImport(MultipartFile[] multipartFiles) throws Exception {
        if (multipartFiles == null || multipartFiles.length < 1){
            return ResultUtil.result(EnumCode.INTERNAL_SERVER_ERROR.getValue(),"空数据,导入失败");
        }
        for (MultipartFile file : multipartFiles){
            List<String[]> list = ExcelUtil.readExcel(file);
            if (list.isEmpty()){
                return ResultUtil.result(EnumCode.INTERNAL_SERVER_ERROR.getValue(),"空数据,导入失败");
            }

            for (int i=0;i<list.size();i++){
                String[] values = list.get(i);
                //这里只导入了3列数据:姓名、邮箱和是否可用(0、1),其他列可自行导入,现转换格式再写入数据库,比如:
                //导入角色的时候,根据角色名称查找角色id,如果角色id不存在,可以默认为学生之类的处理
                User user = new User();
                user.setUsername(values[0]);
                user.setEmail(values[1]);
                user.setEnable(values[2] == null ? 1 : Integer.valueOf(values[2]));
                user.setCreateTime(new Date());
                user.setId(UUID.randomUUID().toString().replace("-",""));
                user.setPassword("a123456");
                user.setRoleId("3");
                userService.addUser(user);
            }
        }
        //前端可以通过状态码,判断文件是否上传成功
        return ResultUtil.result(EnumCode.OK.getValue(),"文件上传成功");
    }

}

6 、获取方式

👇 👇🏻下方点开,扫一扫,关注后,后台回复关键词:学生👇🏻

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

java王不二

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值