基于javaweb的SpringBoot在线网盘系统(java+jsp+springboot+maven+mysql+thymeleaf+ftp)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

250023112402

260023112402

270023112402

280023112402

290023112402

基于javaweb的SpringBoot在线网盘系统(java+jsp+springboot+maven+mysql+thymeleaf+ftp)

一、项目简述

功能:用户的邮箱注册、验证码验证以及用户登录。 不需要注册账号,也可以上传满足条件的临时文件,但是只4小时内有效。 文件的管理,上传、下载、重命名、删除、查看统计数据、分类管理等。 文件夹的管理,创建、删除、重命名。 文件的分享,支持通过链接和二维码的分享方式等等,以及管理员对用户的管理等等。

二、项目运行

环境配置:

Jdk1.8 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +Springboot+ SpringMVC + MyBatis + ThymeLeaf + FTP+ JavaScript + JQuery + Ajax + maven等等

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@Controller
public class LoginController extends BaseController {

private Logger logger = LogUtils.getInstance(LoginController.class);

/**
* @Description 免登陆用户入口,用于本地开发测试,上线运营为了安全请删除此方法
* @Param []
* @return java.lang.String
**/
@GetMapping("/admin")
public String adminLogin(){
User user = userService.getUserByOpenId("123456");
logger.info("使用免登陆方式登录成功!"+user);
session.setAttribute("loginUser", user);
return "redirect:/index";
}

/**
* 用于注册流程,用户名,密码,邮箱等校验工作由前端来完成
*
* @param map 用于存储提示信息
*/
@PostMapping("/register")
public String register(User user, String code, Map<String, Object> map) {
String uCode = (String) session.getAttribute(user.getEmail() + "_code");
if (!code.equals(uCode)) {
map.put("errorMsg", "验证码错误");
return "index";
}
// 用户名去空格
user.setUserName(user.getUserName().trim());
user.setImagePath("https://p.qpic.cn/qqconnect/0/app_101851241_1582451550/100?max-age=2592000&t=0");
user.setRegisterTime(new Date());
user.setRole(1);
if (userService.insert(user)) {
FileStore store = FileStore.builder().userId(user.getUserId()).currentSize(0).build();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 * @Param [map]
* @return java.lang.String
**/
@GetMapping("/video-files")
public String toVideoFilePage( Map<String, Object> map) {
List<MyFile> files = myFileService.getFilesByType(loginUser.getFileStoreId(),3);
//获得统计信息
FileStoreStatistics statistics = myFileService.getCountStatistics(loginUser.getFileStoreId());
map.put("statistics", statistics);
map.put("files", files);
map.put("permission", fileStoreService.getFileStoreByUserId(loginUser.getUserId()).getPermission());
return "u-admin/video-files";
}

/**
* @Description 前往所有音频页面
* @Param [map]
* @return java.lang.String
**/
@GetMapping("/music-files")
public String toMusicFilePage( Map<String, Object> map) {
List<MyFile> files = myFileService.getFilesByType(loginUser.getFileStoreId(),4);
//获得统计信息
FileStoreStatistics statistics = myFileService.getCountStatistics(loginUser.getFileStoreId());
map.put("statistics", statistics);
map.put("files", files);
map.put("permission", fileStoreService.getFileStoreByUserId(loginUser.getUserId()).getPermission());
return "u-admin/music-files";
}

/**
* @Description 前往其他文件页面
* @Param [map]
* @return java.lang.String
**/
@GetMapping("/other-files")
public String toOtherFilePage( Map<String, Object> map) {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 * @Param [fId, fName, error, map]
**/
@GetMapping("/files")
public String toFileStorePage(Integer fId, String fName, Integer error, Map<String, Object> map) {
//判断是否包含错误信息
if (error != null) {
if (error == 1) {
map.put("error", "添加失败!当前已存在同名文件夹");
}
if (error == 2) {
map.put("error", "重命名失败!文件夹已存在");
}
}
//包含的子文件夹
List<FileFolder> folders = null;
//包含的文件
List<MyFile> files = null;
//当前文件夹信息
FileFolder nowFolder = null;
//当前文件夹的相对路径
List<FileFolder> location = new ArrayList<>();
if (fId == null || fId <= 0) {
//代表当前为根目录
fId = 0;
folders = fileFolderService.getRootFoldersByFileStoreId(loginUser.getFileStoreId());
files = myFileService.getRootFilesByFileStoreId(loginUser.getFileStoreId());
nowFolder = FileFolder.builder().fileFolderId(fId).build();
location.add(nowFolder);
} else {
//当前为具体目录,访问的文件夹不是当前登录用户所创建的文件夹
FileFolder folder = fileFolderService.getFileFolderByFileFolderId(fId);
if (folder.getFileStoreId() - loginUser.getFileStoreId() != 0){
return "redirect:/error401Page";
}
//当前为具体目录,访问的文件夹是当前登录用户所创建的文件夹
folders = fileFolderService.getFileFolderByParentFolderId(fId);
files = myFileService.getFilesByParentFolderId(fId);
nowFolder = fileFolderService.getFileFolderByFileFolderId(fId);
//遍历查询当前目录
FileFolder temp = nowFolder;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
            boolean b = FtpUtil.reNameFile(myFile.getMyFilePath() + "/" + oldName+myFile.getPostfix(), myFile.getMyFilePath() + "/" + newName+myFile.getPostfix());
if (b){
Integer integer = myFileService.updateFile(
MyFile.builder().myFileId(myFile.getMyFileId()).myFileName(newName).build());
if (integer == 1){
logger.info("修改文件名成功!原文件名:"+oldName+" 新文件名:"+newName);
}else{
logger.error("修改文件名失败!原文件名:"+oldName+" 新文件名:"+newName);
}
}
}
}
return "redirect:/files?fId="+myFile.getParentFolderId();
}

/**
* @Description 获得二维码
* @Param [id, url]
* @return java.util.Map<java.lang.String,java.lang.Object>
**/
@GetMapping("getQrCode")
@ResponseBody
public Map<String,Object> getQrCode(@RequestParam Integer id,@RequestParam String url){
Map<String,Object> map = new HashMap<>();
map.put("imgPath","https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2654852821,3851565636&fm=26&gp=0.jpg");
if (id != null){
MyFile file = myFileService.getFileByFileId(id);
if (file != null){
try {
String path = request.getSession().getServletContext().getRealPath("/user_img/");
url = url+"/file/share?t="+ UUID.randomUUID().toString().substring(0,10) +"&f="+file.getMyFileId()+"&p="+file.getUploadTime().getTime()+""+file.getSize()+"&flag=1";
File targetFile = new File(path, "");
if (!targetFile.exists()) {
targetFile.mkdirs();
}
File f = new File(path, id + ".jpg");
if (!f.exists()){
//文件不存在,开始生成二维码并保存文件
OutputStream os = new FileOutputStream(f);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
     * @Param [map]
* @return java.lang.String
**/
@GetMapping("/index")
public String index(Map<String, Object> map) {
//获得统计信息
FileStoreStatistics statistics = myFileService.getCountStatistics(loginUser.getFileStoreId());
statistics.setFileStore(fileStoreService.getFileStoreById(loginUser.getFileStoreId()));
map.put("statistics", statistics);
return "u-admin/index";
}

/**
* @Description 前往帮助页面
* @Param [map]
* @return java.lang.String
**/
@GetMapping("/help")
public String helpPage(Map<String, Object> map) {
//获得统计信息
FileStoreStatistics statistics = myFileService.getCountStatistics(loginUser.getFileStoreId());
map.put("statistics", statistics);
return "u-admin/help";
}
}
package com.moti.controller;



/**
* @ClassName: AdminController
* @Description: 管理员控制器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 * @return java.lang.String
**/
@GetMapping("/manages-users")
public String manageUsers(Map<String,Object> map,Integer cur){
if (loginUser.getRole() == 1){
//用于无访问权限
logger.error("当前登录用户:"+loginUser.getUserName()+"无管理员权限!");
return "redirect:/error401Page";
}
//获取全部的用户
Integer usersCount = userService.getUsersCount();
//获取当前查询的页数,如果为空,默认为0
cur = (cur == null || cur<0)?0:cur;
//获得统计信息
FileStoreStatistics statistics = myFileService.getCountStatistics(loginUser.getFileStoreId());
//分页获得20个用户信息
Page<Object> page = PageHelper.startPage(cur, 20);
List<UserToShow> users = userService.getUsers();
map.put("statistics", statistics);
map.put("users", users);
map.put("page", page);
map.put("usersCount", usersCount);
logger.info("用户管理域的内容:"+map);
return "admin/manage-users";
}

/**
* @Description 修改用户的权限和最大容量
* @Param [uId, pre, size]
* @return java.lang.String
**/
@GetMapping("/updateStoreInfo")
@ResponseBody
public String updateStoreInfo(Integer uId,Integer pre,Integer size){
Integer integer = fileStoreService.updatePermission(uId, pre, size*1024);
if (integer == 1) {
//更新成功,返回200状态码
logger.info("修改用户"+userService.queryById(uId).getUserName()+":的权限和仓库大小成功!");
return "200";
}else {
//更新失败,返回500状态码
logger.error("修改用户"+userService.queryById(uId).getUserName()+":的权限和仓库大小失败!");
return "500";
}
}

/**
* @Description 删除用户
* @Param [uId, cur]


项目链接:
https://javayms.github.io?id=051422282105200cg
https://javayms.pages.dev?id=051422282105200cg