文章目录
- 图书借阅管理系统
- 一、项目演示
- 二、项目介绍
- 三、万字文档参考
- 四、系统部分功能截图
- 五、部分代码展示
- 六、底部获取项目和万字文档(9.9¥带走)
图书借阅管理系统
一、项目演示
图书借阅管理系统
二、项目介绍
基于Springboot+vue的前后端分离图书借阅管理系统
开发语言:java
运行环境:idea或eclipse vscode 数据库:mysql
技术:JAVA、 SpringBoot、MyBatis、MySQL、 Vue
本图书借阅管理系统的功能,主要是后端管理系统,角色就分为普通用户和管理员两大角色,
主要功能包括:图书信息管理、图书类别管理、借阅信息管理、用户管理、修改密码、用户借书、用户还书。
三、万字文档参考
四、系统部分功能截图
五、部分代码展示
package com.rabbiter.bms.web;
import com.rabbiter.bms.service.BookInfoService;
import com.rabbiter.bms.utils.MyResult;
import com.rabbiter.bms.utils.MyUtils;
import com.rabbiter.bms.model.BookInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/bookInfo")
public class BookInfoController {
@Autowired
BookInfoService bookInfoService;
// 获取图书数量
@GetMapping(value = "/getCount")
public Integer getCount(){
return bookInfoService.getCount();
}
// 查询所有图书信息
@GetMapping(value = "/queryBookInfos")
public List<BookInfo> queryBookInfos(){
return bookInfoService.queryBookInfos();
}
// 分页搜索查询图书信息 params: {page, limit, bookname, bookauthor, booktypeid}
@GetMapping(value = "/queryBookInfosByPage")
public Map<String, Object> queryBookInfosByPage(@RequestParam Map<String, Object> params){
MyUtils.parsePageParams(params);
int count = bookInfoService.getSearchCount(params); // 获得总数
List<BookInfo> bookInfos = bookInfoService.searchBookInfosByPage(params); // 分页查询
return MyResult.getListResultMap(0, "success", count, bookInfos);
}
// 添加图书信息
@PostMapping(value = "/addBookInfo")
public Integer addBookInfo(@RequestBody BookInfo bookInfo){
return bookInfoService.addBookInfo(bookInfo);
}
// 删除图书信息
@DeleteMapping(value = "/deleteBookInfo")
public Integer deleteBookInfo(@RequestBody BookInfo bookInfo){
return bookInfoService.deleteBookInfo(bookInfo);
}
// 删除一些图书信息
@DeleteMapping(value = "/deleteBookInfos")
public Integer deleteBookInfos(@RequestBody List<BookInfo> bookInfos){
return bookInfoService.deleteBookInfos(bookInfos);
}
// 更新图书信息
@PutMapping(value = "/updateBookInfo")
public Integer updateBookInfo(@RequestBody BookInfo bookInfo){
return bookInfoService.updateBookInfo(bookInfo);
}
}
package com.rabbiter.bms.web;
import com.rabbiter.bms.exception.NotEnoughException;
import com.rabbiter.bms.exception.OperationFailureException;
import com.rabbiter.bms.model.Borrow;
import com.rabbiter.bms.service.BookInfoService;
import com.rabbiter.bms.service.BorrowService;
import com.rabbiter.bms.utils.MyResult;
import com.rabbiter.bms.utils.MyUtils;
import com.rabbiter.bms.model.BookInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/borrow")
public class BorrowController {
@Autowired
BorrowService borrowService;
@Autowired
BookInfoService bookInfoService;
// 分页查询借阅 params: {page, limit, userid, bookid}
@RequestMapping(value = "/queryBorrowsByPage")
public Map<String, Object> queryBorrowsByPage(@RequestParam Map<String, Object> params){
MyUtils.parsePageParams(params);
int count = borrowService.getSearchCount(params);
List<Borrow> borrows = borrowService.searchBorrowsByPage(params);
return MyResult.getListResultMap(0, "success", count, borrows);
}
// 添加借阅
@RequestMapping(value = "/addBorrow")
public Integer addBorrow(@RequestBody Borrow borrow){
return borrowService.addBorrow(borrow);
}
// 获得数量
@RequestMapping(value = "/getCount")
public Integer getCount(){
return borrowService.getCount();
}
// 删除借阅
@RequestMapping(value = "/deleteBorrow")
public Integer deleteBorrow(@RequestBody Borrow borrow){
return borrowService.deleteBorrow(borrow);
}
// 删除一些借阅
@RequestMapping(value = "/deleteBorrows")
public Integer deleteBorrows(@RequestBody List<Borrow> borrows){
return borrowService.deleteBorrows(borrows);
}
// 更新借阅
@RequestMapping(value = "/updateBorrow")
public Integer updateBorrow(@RequestBody Borrow borrow){
return borrowService.updateBorrow(borrow);
}
// 借书
@RequestMapping(value = {"/borrowBook", "/reader/borrowBook"})
@Transactional
public Integer borrowBook(Integer userid, Integer bookid){
try{
// 查询该书的情况
BookInfo theBook = bookInfoService.queryBookInfoById(bookid);
if(theBook == null) { // 图书不存在
throw new NullPointerException("图书" + bookid + "不存在");
} else if(theBook.getIsborrowed() == 1) { // 已经被借
throw new NotEnoughException("图书" + bookid + "库存不足(已经被借走)");
}
// 更新图书表的isBorrowed
BookInfo bookInfo = new BookInfo();
bookInfo.setBookid(bookid);
bookInfo.setIsborrowed((byte) 1);
Integer res2 = bookInfoService.updateBookInfo(bookInfo);
if(res2 == 0) throw new OperationFailureException("图书" + bookid + "更新被借信息失败");
// 添加一条记录到borrow表
Borrow borrow = new Borrow();
borrow.setUserid(userid);
borrow.setBookid(bookid);
borrow.setBorrowtime(new Date(System.currentTimeMillis()));
Integer res1 = borrowService.addBorrow2(borrow);
if(res1 == 0) throw new OperationFailureException("图书" + bookid + "添加借阅记录失败");
} catch (Exception e) {
System.out.println("发生异常,进行手动回滚");
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
e.printStackTrace();
return 0;
}
return 1;
}
// 还书
@RequestMapping(value = {"/returnBook", "/reader/returnBook"})
@Transactional
public Integer returnBook(Integer borrowid, Integer bookid){
try {
// 查询该书的情况
BookInfo theBook = bookInfoService.queryBookInfoById(bookid);
// 查询借书的情况
Borrow theBorrow = borrowService.queryBorrowsById(borrowid);
if(theBook == null) { // 图书不存在
throw new NullPointerException("图书" + bookid + "不存在");
} else if(theBorrow == null) { //结束记录不存在
throw new NullPointerException("借书记录" + bookid + "不存在");
} else if(theBorrow.getReturntime() != null) { // 已经还过书
throw new NotEnoughException("图书" + bookid + "已经还过了");
}
// 更新图书表的isBorrowed
BookInfo bookInfo = new BookInfo();
bookInfo.setBookid(bookid);
bookInfo.setIsborrowed((byte) 0);
Integer res2 = bookInfoService.updateBookInfo(bookInfo);
if(res2 == 0) throw new OperationFailureException("图书" + bookid + "更新被借信息失败");
// 更新Borrow表,更新结束时间
Borrow borrow = new Borrow();
borrow.setBorrowid(borrowid);
borrow.setReturntime(new Date(System.currentTimeMillis()));
Integer res1 = borrowService.updateBorrow2(borrow);
if(res1 == 0) throw new OperationFailureException("图书" + bookid + "更新借阅记录失败");
} catch (Exception e) {
System.out.println("发生异常,进行手动回滚");
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
e.printStackTrace();
return 0;
}
return 1;
}
}
六、底部获取项目和万字文档(9.9¥带走)
有问题,或者需要协助调试运行项目的也可以