Spring+mybatis+Vue的SpringBoot线上网络文件管理系统

108 篇文章 2 订阅

作者主页:源码空间站2022

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

 项目介绍

本项目分为前后台,有管理员与用户两种角色;

管理员角色包含以下功能:

管理员登录,管理员主页,权限管理,分类管理,用户管理,文档管理,下载记录,上传记录等功能。

用户角色包含以下功能:

注册账号,登录,系统首页,我的资源查看,编辑资源,我的资料修改,文件上传,密码重置,邮箱信息,密码重置成功等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
5.数据库:MySql 8.0/5.7版本;

6.是否Maven项目:是;

技术栈

HTML+CSS+JavaScript+mysql+Spring+SpringMVC+mybatis+Spring boot+vue

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;

4. 运行项目,输入http://localhost:18091 登录

运行截图

前台界面

后台界面

相关代码

权限控制器

@RestController
@RequestMapping("/auth")
@Api(value = "/auth", description = "权限表相关操作")
public class AuthController {

    private final IAuthService authService;

    @Autowired
    public AuthController(IAuthService authService) {this.authService = authService;}

    @ApiOperation(value = "添加权限记录", notes = "设置指定用户对指定文件的权限")
    @ApiImplicitParams({@ApiImplicitParam(name = "files", value = "文件", example = "file1,file2,file3", required = true),
            @ApiImplicitParam(name = "users", value = "用户", example = "user1,user2,user3", required = true),
            @ApiImplicitParam(name = "auths", value = "权限", example = "1,1,1,1", required = true)})
    @AuthInterceptor(InterceptorLevel.ADMIN)
    @RequestMapping(value = "", method = RequestMethod.POST)
    public String add(String files, String users, String auths) {
        System.out.println("files: " + files + " users: " + users + " auths: " + auths);
        return ControllerUtils.getResponse(authService.addAuth(files, users, auths));
    }

    @ApiOperation(value = "获取权限记录")
    @ApiImplicitParams({@ApiImplicitParam(name = "user", value = "用户", required = true), @ApiImplicitParam(name =
            "file", value = "文件", required = true), @ApiImplicitParam(name = "offset", value = "偏移量", required = true)})
    @AuthInterceptor(InterceptorLevel.ADMIN)
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public String getAuth(String user, String file, int offset) {
        return Formatter.listToJson(authService.listAuth(user, file, offset));
    }

    @ApiOperation(value = "更新权限记录")
    @ApiImplicitParams({@ApiImplicitParam(name = "auth", value = "权限值", required = true)})
    @AuthInterceptor(InterceptorLevel.ADMIN)
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public String updateAuth(@PathVariable("id") long id, String auth) {
        return ControllerUtils.getResponse(authService.updateAuth(id, auth));
    }

    @ApiOperation(value = "批量删除权限记录")
    @AuthInterceptor(InterceptorLevel.ADMIN)
    @RequestMapping(value = "/batch/{ids}", method = RequestMethod.DELETE)
    public String batchDelete(@PathVariable("ids") String ids) {
        return ControllerUtils.getResponse(authService.batchDelete(ids));
    }
}

分类控制器

@RestController
@RequestMapping("/category")
@Api(value = "/category", description = "文件分类相关操作")
public class CategoryController {

    private final ICategoryService categoryService;

    @Autowired
    public CategoryController(ICategoryService categoryService) {this.categoryService = categoryService;}

    @ApiOperation(value = "新增一个分类")
    @AuthInterceptor(InterceptorLevel.ADMIN)
    @RequestMapping(value = "/{name}", method = RequestMethod.POST)
    public String add(@PathVariable("name") String name) {
        return ControllerUtils.getResponse(categoryService.insert(name));
    }

    @ApiOperation(value = "更新分类名称")
    @ApiImplicitParam(name = "name", value = "新的名称", required = true)
    @AuthInterceptor(InterceptorLevel.ADMIN)
    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public String update(@PathVariable("id") int id, String name) {
        boolean isSuccess = Checker.isNotEmpty(name) && categoryService.update(id, name);
        return ControllerUtils.getResponse(isSuccess);
    }

    @ApiOperation(value = "删除一个分类")
    @AuthInterceptor(InterceptorLevel.ADMIN)
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String remove(@PathVariable("id") int id) {
        return ControllerUtils.getResponse(categoryService.remove(id));
    }

    @ApiOperation(value = "获取一个分类")
    @AuthInterceptor(InterceptorLevel.NONE)
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String getById(@PathVariable("id") int id) {
        Category category = categoryService.getById(id);
        if (Checker.isNull(category)) {
            return ControllerUtils.getResponse(ValueConsts.FALSE);
        } else {
            return category.toString();
        }
    }

    @ApiOperation(value = "获取所有分类")
    @AuthInterceptor(InterceptorLevel.NONE)
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public String getAll() {
        return Formatter.listToJson(categoryService.list());
    }
}

公共接口控制器

@RestController
@RequestMapping("/common")
@Api(value = "/common", description = "公共接口")
public class CommonController {

    private static Logger logger = LoggerFactory.getLogger(ConfigController.class);

    private final ICommonService commonService;

    private final HttpServletRequest request;

    @Autowired
    private IUserService userService;
    
    private final JSONObject jsonObject;

    @Autowired
    public CommonController(ICommonService commonService, HttpServletRequest request, JSONObject jsonObject) {
        this.commonService = commonService;
        this.request = request;
        this.jsonObject = jsonObject;
    }

    @ApiOperation(value = "获取头像资源")
    @AuthInterceptor(InterceptorLevel.NONE)
    @RequestMapping(value = "/avatar/{name}", method = RequestMethod.GET)
    public void getAvatar(HttpServletResponse response, @PathVariable("name") String name) throws IOException {
        String path = SettingConfig.getAvatarStoragePath() + ValueConsts.SEPARATOR + name;
        ControllerUtils.loadResource(response, path, ValueConsts.FALSE);
    }

    @ApiOperation(value = "上传头像")
    @ApiImplicitParam(name = "multipartFile", value = "头像", required = true)
    @AuthInterceptor(InterceptorLevel.USER)
    @RequestMapping(value = "/avatar", method = RequestMethod.POST)
    public String avatarUpload(@RequestParam("file") MultipartFile multipartFile) {
        String name = commonService.uploadAvatar(multipartFile);
        User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
        user.setAvatar("/common/avatar/" + name);
        userService.updateBasicInfoById(user.getId(), user.getAvatar(), user.getRealName(), user.getEmail());
        if (Checker.isEmpty(name)) {
            jsonObject.put("error", "文件格式不合法");
        } else {
            jsonObject.put("success", "/common/avatar/" + name);
        }
        return jsonObject.toString();
    }

    @ApiOperation(value = "发送验证码")
    @AuthInterceptor(InterceptorLevel.NONE)
    @RequestMapping(value = "/{email}/code", method = RequestMethod.POST)
    public String sendVerifyCode(@PathVariable("email") String email) {
        int code = commonService.sendVerifyCode(email);
        if (code > 0) {
            request.getSession().setAttribute(DefaultValues.CODE_STRING, code);
            logger.info("verify code: " + code);
            jsonObject.put("status", "success");
        } else {
            jsonObject.put("status", "error");
        }
        return jsonObject.toString();
    }

    @ApiOperation(value = "验证验证码是否正确")
    @AuthInterceptor(InterceptorLevel.NONE)
    @RequestMapping(value = "/{code}/verification", method = RequestMethod.PUT)
    public String verifyCode(@PathVariable("code") String code) {
        boolean isSuccess = Checker.checkNull(code).equals(String.valueOf(request.getSession().getAttribute
                (DefaultValues.CODE_STRING)));
        return ControllerUtils.getResponse(isSuccess);
    }
}

文件管理控制器

@ApiIgnore
@RestController
@RequestMapping("/filemanager")
@AuthInterceptor(InterceptorLevel.SYSTEM)
public class FileMangerController {

    private final IFileManagerService fileManagerService;

    private final JSONObject jsonObject;

    @Autowired
    public FileMangerController(IFileManagerService fileManagerService, JSONObject jsonObject) {
        this.fileManagerService = fileManagerService;
        this.jsonObject = jsonObject;
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/multidownload", method = RequestMethod.GET)
    public void multiDownload(HttpServletResponse response, String[] items, String toFilename) throws IOException {
        ControllerUtils.setResponseFileName(response, toFilename);
        fileManagerService.multiDownload(response, items, toFilename);
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/download", method = RequestMethod.GET)
    public void download(HttpServletResponse response, String path) throws IOException {
        ControllerUtils.loadResource(response, path, ValueConsts.TRUE);
    }

    /**
     * 暂时没有找到更好的解决方案
     *
     * @param destination 目的
     *
     * @return 响应结果
     */
    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public String upload(String destination, MultipartHttpServletRequest request) {
        Map<String, MultipartFile> fileMap = request.getFileMap();
        MultipartFile[] files = ArrayUtils.mapToArray(fileMap, MultipartFile.class);
        jsonObject.put("result", fileManagerService.upload(destination, files));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/extract", method = RequestMethod.POST)
    public String extract(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.extract(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/compress", method = RequestMethod.POST)
    public String compress(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.compress(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/permission", method = RequestMethod.POST)
    public String setPermission(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.setPermission(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/folder", method = RequestMethod.POST)
    public String createFolder(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.createFolder(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/content", method = RequestMethod.POST)
    public String getContent(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.getContent(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public String edit(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.edit(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public String remove(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.remove(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/copy", method = RequestMethod.POST)
    public String copy(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.copy(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/move", method = RequestMethod.POST)
    public String move(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.move(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/rename", method = RequestMethod.POST)
    public String rename(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.rename(json));
        return jsonObject.toJSONString();
    }

    @AuthInterceptor(InterceptorLevel.SYSTEM)
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public String list(@RequestBody JSONObject json) {
        jsonObject.put("result", fileManagerService.list(json));
        return jsonObject.toJSONString();
    }
}

如果也想学习本系统,下面领取。回复:094springboot

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值