基于javaweb的SpringBoot图书管理系统(java+springboot+jsp+bootstrap+maven+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

520023052402

530023052402

540023052402

550023052402

560023052402

570023052402

基于javaweb的SpringBoot图书管理系统(java+springboot+jsp+bootstrap+maven+mysql)

项目介绍

本系统分为管理员与普通用户两种角色; 管理员角色包含以下功能: 借书管理,图书信息管理,图书分类管理,用户管理,角色管理,还书管理,登录页面等功能。

用户角色包含以下功能:借阅管理,图书检索,查看借还记录,查看图书详情,还书管理,登录页面等功能。

环境需要

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

技术栈

  1. 后端:SpringBoot

  2. 前端:JSP+CSS+JavaScript+bootstrap

使用说明
运行项目,在浏览器中输入localhost:8083/ 登录

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
/**
* @param file
* @return : java.util.Map<java.lang.String,java.lang.Object>
* @description: 文件上传
*/
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> uploadFile(MultipartFile file) throws Exception {
Map<String, Object> map = new HashMap<>();
if (!file.isEmpty()) {
// 获取文件名
String fileName = file.getOriginalFilename();
// 获取文件的后缀名
String suffixName = fileName.substring(fileName.lastIndexOf("."));
String newFileName = UUID.randomUUID() + suffixName;

Date date = new Date();
int hashcode = fileName.hashCode();
int dir1 = hashcode & 0xf; //0--15
int dir2 = (hashcode & 0xf0) >> 4; //0--15
String path = uploadFilePath + new SimpleDateFormat("yyyy/MM/dd").format(date) + "/" + dir1 + "/" + dir2 + "/";
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + newFileName));
map.put("code", 0);
map.put("msg", "上传成功");
System.out.println("http://localhost:8080/uploads/" + new SimpleDateFormat("yyyy/MM/dd").format(date) + "/" + dir1 + "/" + dir2 + "/" + newFileName);
}
return map;
}


/**
* @param file
* @param CKEditorFuncNum
* @return : java.lang.String
* @description: ckeditor上传
*/
@RequestMapping(value = "/ckeditorUpload", method = RequestMethod.POST)
@ResponseBody
public String ckeditorUpload(@RequestParam("upload") MultipartFile file, String CKEditorFuncNum) throws IOException {
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
        bookInfoDataGridDataSource.setRows(bookInfoList);
return bookInfoDataGridDataSource;
}


/**
* @param bookId
* @return : io.hailiang.web.book.common.JsonData
* @description: 图书详情
*/
@GetMapping("/detail")
@LoginRequired
public JsonData bookInfoDetail(Integer bookId) {
List<BookInfo> bookInfos = bookInfoService.selectBookById(bookId);
for (BookInfo bookInfo : bookInfos) {
List<BookType> bookTypeList = bookTypeService.selectBookTypeListByBookTypeId(bookInfo.getBookType());
for (BookType bookType : bookTypeList) {
bookInfo.setTypes(bookType.getBookTypeName());
}
}
return JsonData.success(bookInfos);
}


/**
* @param bookId
* @return : io.hailiang.web.book.common.JsonData
* @description: 图书信息(借书管理)
*/
@PostMapping("/info")
@LoginRequired
public JsonData bookInfo(Integer bookId) {
return JsonData.success(bookInfoService.selectBookInfoById(bookId));
}
}
package io.hailiang.web.book.controller;

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
 * @description: 根据id删除用户
*/
@DeleteMapping("/delete")
@LoginRequired
public JsonData deleteUser(@RequestParam(value = "userId") Long userId) {
//TODO 删除用户前先根据用户id将用户角色关联表的记录删除
roleService.deleteRoleUserRsByUserId(userId);
int count = userService.deleteUser(userId);
if (count > 0) {
return JsonData.success(count, "删除成功");
} else {
return JsonData.fail("删除失败");
}
}


/**
* @param toMail
* @param userId
* @return : io.hailiang.web.book.common.JsonData
* @description: 重置用户密码并发送邮件
*/
@PostMapping("/sendMail")
@LoginRequired
public JsonData sendMail(@RequestParam(value = "toMail") String toMail,
@RequestParam(value = "userId") Long userId) {
if (StringUtils.isEmpty(toMail)) {
return JsonData.fail("用户邮箱不能为空");
}
//TODO 随机生成密码
String defaultPassword = PasswordCreateUtil.createPassWord(8);
User user = new User();
user.setUserId(userId);
user.setUserPassword(defaultPassword);
int count = userService.updateUser(user);
if (count > 0) {
mailService.sendSimpleMail(toMail, "重置密码", "您的初始密码为:" + defaultPassword);
return JsonData.success(count, "重置密码成功");
} else {
return JsonData.fail("重置密码失败");
}
}


/**
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
        StringBuffer stringBuffer = new StringBuffer();
for (Role role : roleList) {
stringBuffer.append("," + role.getRoleName());
}
user.setRoles(stringBuffer.toString().replaceFirst(",", ""));
session.setAttribute("user", user);
// 获取用户权限信息
List<Permission> permissions = permissionService.queryPermissionsByUser(user);
Map<Integer, Permission> permissionMap = new HashMap<>();
Permission root = null;
Set<String> uriSet = new HashSet<>();
for (Permission permission : permissions) {
permissionMap.put(permission.getPermissionId(), permission);
if (permission.getPermissionUrl() != null && !"".equals(permission.getPermissionUrl())) {
uriSet.add(permission.getPermissionUrl());
}
}
session.setAttribute("authUriSet", uriSet);
for (Permission permission : permissions) {
Permission child = permission;
if (child.getPermissionParentId() == null) {
root = permission;
} else {
Permission parent = permissionMap.get(child.getPermissionParentId());
parent.getChildren().add(child);
}
}
session.setAttribute("rootPermission", root);
return JsonData.success();
} else {
return JsonData.fail("用户名或密码错误!");
}
}


/**
* @param user
* @return : io.hailiang.web.book.common.JsonData
* @description: 新增用户
*/
@PostMapping("/save")
@LoginRequired
public JsonData saveUser(User user) {
int count = userService.saveUser(user);
if (count > 0) {
return JsonData.success(count, "添加成功");
} else {
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
public JsonData updateUser(User user) {
int count = userService.updateUser(user);
if (count > 0) {
return JsonData.success(count, "更新成功");
} else {
return JsonData.fail("更新失败");
}

}

/**
* @param userId
* @return : io.hailiang.web.book.common.JsonData
* @description: 根据id删除用户
*/
@DeleteMapping("/delete")
@LoginRequired
public JsonData deleteUser(@RequestParam(value = "userId") Long userId) {
//TODO 删除用户前先根据用户id将用户角色关联表的记录删除
roleService.deleteRoleUserRsByUserId(userId);
int count = userService.deleteUser(userId);
if (count > 0) {
return JsonData.success(count, "删除成功");
} else {
return JsonData.fail("删除失败");
}
}


/**
* @param toMail
* @param userId
* @return : io.hailiang.web.book.common.JsonData
* @description: 重置用户密码并发送邮件
*/
@PostMapping("/sendMail")
@LoginRequired
public JsonData sendMail(@RequestParam(value = "toMail") String toMail,
@RequestParam(value = "userId") Long userId) {
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
50
51
52
    //更新图书状态为借出
BookInfo bookInfo = new BookInfo();
bookInfo.setBookId(lendReturnList.getBookId());
bookInfo.setBookState(1);

bookInfoService.updateBookInfo(bookInfo);
if (i > 0) {
return JsonData.success(i, "借阅成功");
} else {
return JsonData.fail("借阅失败");
}

}


/**
*
* @param page
* @param rows
* @param session
* @return : io.hailiang.web.book.common.DataGridDataSource<io.hailiang.web.book.model.LendReturnList>
* @description: 根据用户ID查询借还记录
*/
@PostMapping("/lendreturnrecord")
@LoginRequired
public DataGridDataSource<LendReturnList> selectLendReturnRecordByUserId(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
@RequestParam(value = "rows", required = false, defaultValue = "5") Integer rows,
HttpSession session) throws ParseException {

User currentUser = (User) session.getAttribute("user");
PageBean pageBean = new PageBean(page, rows);
Map<String, Object> map = new HashMap<>();
map.put("userId", currentUser.getUserId());
map.put("start", pageBean.getStart());
map.put("size", pageBean.getPageSize());
List<LendReturnList> lendReturnLists = lendBookService.selectLendReturnRecordByUserId(map);
int totalRecord = lendBookService.getTotalRecord(map);
DataGridDataSource<LendReturnList> list = new DataGridDataSource<>();
list.setTotal(totalRecord);
list.setRows(lendReturnLists);
return list;
}

@PostMapping("/lendreturnrecordAll")
@LoginRequired
public DataGridDataSource<LendReturnList> lendreturnrecordAll(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
@RequestParam(value = "uid", required = false) Long uid,
@RequestParam(value = "rows", required = false, defaultValue = "5") Integer rows,
HttpSession session) throws ParseException {

PageBean pageBean = new PageBean(page, rows);
Map<String, Object> map = new HashMap<>();


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