vuereact & vue & angularspringboot

SSM SpringBoot vue电子班牌系统

2022-09-17  本文已影响0人  beyond阿亮

SSM SpringBoot vue电子班牌系统

SSM 电子班牌系统功能介绍

首页 图片轮播 课程信息 通知公告 登录注册 个人中心 我的收藏 我的后台

后台管理 登录注册 个人中心 学生管理 教师管理 通知公告管理 班级信息管理
课程状态管理 系统图片管理 管理员管理 课程信息管理 选课信息管理

使用技术

功能展示

首页.jpg 通知公告.jpg 登录.jpg 个人中心.jpg 后台登录.jpg 课程信息管理.jpg 班级信息管理.jpg 选课信息管理.jpg 学生管理.jpg

文件上传下载FileController.java

package com.controller;

import java.io.File;
import java.io.IOException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.ConfigEntity;
import com.entity.EIException;
import com.service.ConfigService;
import com.utils.R;

/**
 * 上传文件
 */
@RestController
@RequestMapping("file")
@SuppressWarnings({"unchecked","rawtypes"})
public class FileController{
    @Autowired
    private ConfigService configService;

    /**
     * 上传文件
     */
    @RequestMapping("/upload")
    public R upload(@RequestParam("file") MultipartFile file, String type,HttpServletRequest request) throws Exception {
        if (file.isEmpty()) {
            throw new EIException("上传文件不能为空");
        }
        String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
        String fileName = new Date().getTime()+"."+fileExt;
        File dest = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName);
        file.transferTo(dest);
        if(StringUtils.isNotBlank(type) && type.equals("1")) {
            ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
            if(configEntity==null) {
                configEntity = new ConfigEntity();
                configEntity.setName("faceFile");
                configEntity.setValue(fileName);
            } else {
                configEntity.setValue(fileName);
            }
            configService.insertOrUpdate(configEntity);
        }
        return R.ok().put("file", fileName);
    }
    
    /**
     * 下载文件
     */
    @IgnoreAuth
    @RequestMapping("/download")
    public void download(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) {
        try {
            File file = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName);
            if (file.exists()) {
                response.reset();
                response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName+"\"");
                response.setHeader("Cache-Control", "no-cache");
                response.setHeader("Access-Control-Allow-Credentials", "true");
                response.setContentType("application/octet-stream; charset=UTF-8");
                IOUtils.write(FileUtils.readFileToByteArray(file), response.getOutputStream());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
}

运行

创建数据库, 然后修改数据库连接相关信息。

配置tomcat运行

前台访问地址:http://localhost:8080/ssm/front/index.html

后台访问地址:http://localhost:8080/ssm/admin/dist/index.html

管理员账号:liang 密码:liang

上一篇 下一篇

猜你喜欢

热点阅读