基于javaweb+mysql的ssm+maven图书借阅管理系统(管理员、普通用户)(java+jsp+ssm+javabean+mysql+tomcat+javascript)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSM+Maven图书借阅管理系统(管理员、普通用户)(java+jsp+ssm+javabean+mysql+tomcat+javascript)
首页:
管理员:
admin 123456
用户:
user1 123456
user2 123456
@RequestMapping("/page")
String page() {
return "/WEB-INF/page/bookManagement/bookManagementMain.jsp";
}
@RequestMapping("/bookAdd")
String bookAdd(RedirectAttributes redirectAttributes, Model model) {
model.addAttribute("msg", redirectAttributes.getAttribute("msg"));
return "/WEB-INF/page/bookManagement/bookAdd.jsp";
}
@RequestMapping("/bookDelete")
String bookDelete() {
return "/WEB-INF/page/bookManagement/bookDelete.jsp";
}
@RequestMapping("/bookUpdate")
String bookChange() {
return "/WEB-INF/page/bookManagement/bookUpdate.jsp";
}
@RequestMapping("/bookQuery")
String bookQuery() {
return "/WEB-INF/page/bookManagement/bookQuery.jsp";
}
@RequestMapping("/UpdateDate/{bookId}")
String bookUpdateSubmit(@PathVariable int bookId,Model model) {
Book book = bookManService.getBookById(bookId);
model.addAttribute("book",book);
return "/WEB-INF/page/bookManagement/bookUpdateSubmit.jsp";
}
@Autowired
BookManService bookManService;
@PostMapping("/addBook")
String addBook(/*@RequestBody*/ Book book, RedirectAttributes redirectAttributes) {
int i = bookManService.addBook(book);
if (i == -1) {
redirectAttributes.addFlashAttribute("msg", "添加失败");
return "redirect:/searchcontroller/bookAdd";
} else {
redirectAttributes.addFlashAttribute("msg", "添加成功");
return "redirect:/searchcontroller/page";
}
}
@PostMapping("/deleteBook")
String deleteBook(int ids, RedirectAttributes redirectAttributes) {
System.out.println(ids);
int number = bookManService.deleteByIds(ids);
if (number == -1) {
redirectAttributes.addFlashAttribute("msg", "删除失败");
}
@RequestMapping("/tiaozhuan")
String tiaozhuan(){
return "/WEB-INF/page/userManagement/User.jsp";
}
@Autowired
ReaderServices readerServices;
@PostMapping("/adduser")
String adduser(User user,RedirectAttributes redirectAttributes){
boolean i = readerServices.adduser(user);
if (i == false) {
redirectAttributes.addFlashAttribute("msg", "添加失败");
return "redirect:/ReaderController/jumpAdd";
} else {
redirectAttributes.addFlashAttribute("msg", "添加成功");
return "redirect:/ReaderController/tiaozhuan";
}
}
@PostMapping ("/deleteUser")
String deleteUser(int ids,RedirectAttributes redirectAttributes) {
System.out.println(ids);
int number = readerServices.deleteByIds(ids);
if (number == 0) {
redirectAttributes.addFlashAttribute("msg", "删除失败");
return "redirect:/reader/deleteUser";
} else {
redirectAttributes.addFlashAttribute("msg", "删除成功");
return "redirect:/reader/Page";
}
}
@RequestMapping("/Page")
String Page()
{
return "/WEB-INF/page/userManagement/User.jsp";
}
@ResponseBody
@RequestMapping("/queryuser")
public List<User> queryuser(String keywords){
return readerService.queryuser(keywords);
}
*/
@PostMapping ("/returnBook")
@ResponseBody
Result returnBook(int borrowingId,int isReturn,boolean isTimeout){
String s = null;
try {
s = borrowingServices.returnBook(borrowingId, isReturn, isTimeout);
} catch (Exception e) {
return ResultFactory.getFail(e.getMessage());
}
return ResultFactory.getSucceed(s);
}
/**
* <h2>取消预约方法</h2>
*/
@ResponseBody
@PostMapping("/cancelAnAppointment")
Result cancelAnAppointment(int borrowingId){
try {
borrowingServices.cancelAnAppointment(borrowingId);
} catch (Exception e) {
Result fail = ResultFactory.getFail();
fail.setMessage(e.getMessage());
return fail;
}
return ResultFactory.getSucceed("取消成功");
}
/**
* <h2>预约借书方法控制器</h2>
*/
@ResponseBody
@PostMapping("/bookingLibrary")
Result bookingLibrary(int borrowingId){
return ResultFactory.getSucceed(borrowingServices.bookingLibrary(borrowingId));
}
}
/**<h2>页面访问</h2>*/
@RequestMapping("/page")
String borrowingRecords(){
return "/WEB-INF/page/borrowingManagement/BorrowingRecords.jsp";
}
@Autowired
BorrowingServices borrowingServices;
/**
* <h2>获取借书记录</h2>
*/
@ResponseBody
@GetMapping("/{userId}")
Result borrowingRecords( @PathVariable int userId){
Result succeed = ResultFactory.getSucceed();
List<UserBorrowingInfo> userBorrowingInfoList = borrowingServices.getUserBorrowingInfoByUserId(userId);
succeed.addData("userBorrowingInfoList",userBorrowingInfoList);
return succeed;
}
/**
* <h2>还书请求处理方法</h2>
*/
@PostMapping ("/returnBook")
@ResponseBody
Result returnBook(int borrowingId,int isReturn,boolean isTimeout){
String s = null;
try {
s = borrowingServices.returnBook(borrowingId, isReturn, isTimeout);
} catch (Exception e) {
return ResultFactory.getFail(e.getMessage());
}
return ResultFactory.getSucceed(s);
}
/**
* <h2>取消预约方法</h2>
*/
@ResponseBody
@PostMapping("/cancelAnAppointment")
Result cancelAnAppointment(int borrowingId){
try {
borrowingServices.cancelAnAppointment(borrowingId);
} catch (Exception e) {
Result fail = ResultFactory.getFail();
fail.setMessage(e.getMessage());
return fail;
}
return ResultFactory.getSucceed("取消成功");
}
/**
* <h1>借阅记录控制器</h1>
*/
@Controller
@RequestMapping("/borrowingRecords")
public class RecordsBorrowingController {
/**<h2>页面访问</h2>*/
@RequestMapping("/page")
String borrowingRecords(){
return "/WEB-INF/page/borrowingManagement/BorrowingRecords.jsp";
}
@Autowired
BorrowingServices borrowingServices;
/**
* <h2>获取借书记录</h2>
*/
@ResponseBody
@GetMapping("/{userId}")
Result borrowingRecords( @PathVariable int userId){
Result succeed = ResultFactory.getSucceed();
List<UserBorrowingInfo> userBorrowingInfoList = borrowingServices.getUserBorrowingInfoByUserId(userId);
succeed.addData("userBorrowingInfoList",userBorrowingInfoList);
return succeed;
}
}
// 修改读者信息
@RequestMapping("/doUpdate")
public String doUpdate(User user1) {
readerService.updateUser(user1);
return "redirect:/reader/list";
}
@RequestMapping("/tiaozhuan")
String tiaozhuan(){
return "/WEB-INF/page/userManagement/User.jsp";
}
@Autowired
ReaderServices readerServices;
@PostMapping("/adduser")
String adduser(User user,RedirectAttributes redirectAttributes){
boolean i = readerServices.adduser(user);
if (i == false) {
redirectAttributes.addFlashAttribute("msg", "添加失败");
return "redirect:/ReaderController/jumpAdd";
} else {
redirectAttributes.addFlashAttribute("msg", "添加成功");
return "redirect:/ReaderController/tiaozhuan";
}
}
@PostMapping ("/deleteUser")
String deleteUser(int ids,RedirectAttributes redirectAttributes) {
System.out.println(ids);
int number = readerServices.deleteByIds(ids);
if (number == 0) {
redirectAttributes.addFlashAttribute("msg", "删除失败");
return "redirect:/reader/deleteUser";
} else {
redirectAttributes.addFlashAttribute("msg", "删除成功");
return "redirect:/reader/Page";
}
}
@RequestMapping("/Page")
String Page()
{
return "/WEB-INF/page/userManagement/User.jsp";
}
@ResponseBody
@RequestMapping("/queryuser")
@ResponseBody
@RequestMapping("/bookrank")
public List<Map<String, Object>> BookRank(Model model){
return inforRank.BorrowRank();
}
@ResponseBody
@RequestMapping("/bookrankbytype")
public List<Map<String,Object>> BookBookByType(){return inforRank.BookRankByType();}
@RequestMapping("/readerborrow")
public String ReaderBorrow(){
return "/WEB-INF/page/InformationStatistics/ReaderRank.jsp";
}
@ResponseBody
@RequestMapping("/readerrank")
public List<Map<String,Object>> ReaderRank(){return inforRank.ReaderRank();}
@RequestMapping("/bookingpage")
public String BookingPage(){return "/WEB-INF/page/InformationStatistics/BookingStatistic.jsp";}
@ResponseBody
@RequestMapping("/bookingstatistic")
public List<Map<String,Object>> BookingStatistic(){return inforRank.BookingStatistic();}
@ResponseBody
@GetMapping("/pricepageNum/{pageNo}")
public Page<Map<String,Object>> PriceInfor(@PathVariable int pageNo){return toTalInfor.ReceiveByPrice(pageNo,5,5);}
@ResponseBody
@RequestMapping("/typepageNum/{pageNo}")
public Page<Map<String,Object>> TypeInfor(@PathVariable int pageNo){return toTalInfor.ReceiveByType(pageNo,5);}
}
/**
* <h1>登录拦截器</h1>
* 限制用户,不登陆无法访问的页面
*/
@Component
public class LoginInterceptor implements HandlerInterceptor {
/**
* <h2>前置处理</h2>
* */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HttpSession session = request.getSession();
//若登录信息为空,即 用户未登录
Object userLoginInfo = request.getSession().getAttribute("USER_LOGIN_INFO");
if(userLoginInfo == null){
// 用户未登录,重定向到登录页面
String uri = request.getRequestURI();//获取请求来源地址
String query = request.getQueryString();//获取查询字符串
session.setAttribute("REQUEST_URI", uri + (query == null ? "" : "?" + query));
response.sendRedirect("/login?msg="+ URLEncoder.encode("你还没有登陆,请先登录。。。", "UTF-8"));
return false;
}
return HandlerInterceptor.super.preHandle(request, response, handler);
}
}
/**
* <h1>管理员拦截器</h1>
* 限制用户,只有管理员可以访问
*/
@Component
public class RootInterceptor implements HandlerInterceptor {
/**
* <h2>前置处理</h2>
@RequestMapping("/bookAdd")
String bookAdd(RedirectAttributes redirectAttributes, Model model) {
model.addAttribute("msg", redirectAttributes.getAttribute("msg"));
return "/WEB-INF/page/bookManagement/bookAdd.jsp";
}
@RequestMapping("/bookDelete")
String bookDelete() {
return "/WEB-INF/page/bookManagement/bookDelete.jsp";
}
@RequestMapping("/bookUpdate")
String bookChange() {
return "/WEB-INF/page/bookManagement/bookUpdate.jsp";
}
@RequestMapping("/bookQuery")
String bookQuery() {
return "/WEB-INF/page/bookManagement/bookQuery.jsp";
}
@RequestMapping("/UpdateDate/{bookId}")
String bookUpdateSubmit(@PathVariable int bookId,Model model) {
Book book = bookManService.getBookById(bookId);
model.addAttribute("book",book);
return "/WEB-INF/page/bookManagement/bookUpdateSubmit.jsp";
}
@Autowired
BookManService bookManService;
@PostMapping("/addBook")
String addBook(/*@RequestBody*/ Book book, RedirectAttributes redirectAttributes) {
int i = bookManService.addBook(book);
if (i == -1) {
redirectAttributes.addFlashAttribute("msg", "添加失败");
return "redirect:/searchcontroller/bookAdd";
} else {
redirectAttributes.addFlashAttribute("msg", "添加成功");
return "redirect:/searchcontroller/page";
}
}
@PostMapping("/deleteBook")
String deleteBook(int ids, RedirectAttributes redirectAttributes) {
System.out.println(ids);
int number = bookManService.deleteByIds(ids);
if (number == -1) {
redirectAttributes.addFlashAttribute("msg", "删除失败");
return "redirect:/searchcontroller/deleteBook";
} else {
*/
@ResponseBody
@GetMapping("/getBorrowingRecent/{bookId}")
Result getBorrowingRecent(@PathVariable int bookId){
int borrowingRecent = bookService.getBorrowingRecent(bookId);
Result result = ResultFactory.getSucceed();
result.addData("borrowingRecent",borrowingRecent);
return result;
}
@Autowired
BorrowingServices borrowingServices;
/**
* 超时记录
* */
@ResponseBody
@GetMapping("/getTimeoutLogging")
Result getTimeoutLogging(int userId){
List<UserBorrowingInfo> userTimeoutLogging = borrowingServices.getUserTimeoutLogging(userId);
Result succeed = ResultFactory.getSucceed();
succeed.addData("timeoutLogging",userTimeoutLogging);
return succeed;
}
/**
* 借阅数量
* */
@ResponseBody
@GetMapping("/getBorrowingTotalTotal")
Result getBorrowingTotalTotal(int userId){
int userBorrowingTotal = borrowingServices.getUserBorrowingTotal(userId);
Result succeed = ResultFactory.getSucceed();
succeed.addData("borrowedsTotal",userBorrowingTotal);
return succeed;
}
/**
* <h2>借阅请求方法</h2>
* 获取当前时间,其他信息由前端页面给予
*/
@ResponseBody
@PostMapping("/newBorrowing")
Result newBorrowing(/*@DateTimeFormat(pattern = "YYYY-MM-DD'T'HH:mm")*/ @RequestBody Borrowing borrowing){
// System.out.println(borrowing);//test
boolean isBorrowingSucceed = true;
String message="";
try {
borrowingServices.borrowing(borrowing);
}
}
/**
* <h1>借阅中心控制器</h1>
*/
@Controller
@RequestMapping("/borrowing")
public class BorrowingController {
@Autowired
BookService bookService;
/*=========================================书籍信息展示页面==========================================================*/
/**
* <h2>接收访问请求</h2>
* 将普通用户与管理员区分;将用户信息发送给前端页面;
*/
@GetMapping
String borrowingPage(HttpSession session, Model model){
return "forward:/borrowing/userBorrowing";
}
// @GetMapping("/rootBorrowing")
// String rootBorrowingPage() {
// return "/WEB-INF/page/borrowingManagement/RootBorrowing.jsp";
// }
@RequestMapping("/UpdateBook")
public String UpdateBook(Book book,Model model) {
// 更新图书信息
// try {
bookManService.bookUpdate(book);
// } catch (Exception e) {
// model.addAttribute("msg",e);
// return "redirect:/searchcontroller/UpdateDate/"+book.getBookId();
// }
model.addAttribute("msg","图书修改成功!");
return "redirect:/searchcontroller/bookUpdate";
}
}
/**
* <h1>登录控制器</h1>
*/
@Controller
@RequestMapping("/login")
public class LoginController{
@Autowired
UserService userService;
@GetMapping
String loginPage(Model model,@ModelAttribute("msg") String msg){
return "/WEB-INF/page/Login.jsp";
}
/**
* <h2>登陆执行控制器</h2>
*/
@PostMapping("/execute")
String login(String userName, String userPassword,HttpSession session){
@RequestMapping("/usercenter")
public class UserCenterController {
@Autowired
InforService inforService;
@Autowired
ToTalInfor toTalInfor;
@Autowired
InforRank inforRank;
@RequestMapping("/userpage")
public String userpage(Model model, HttpServletRequest req, HttpServletResponse resp,HttpSession session) {
UserLoginInfo userLoginInfo = (UserLoginInfo) session.getAttribute("USER_LOGIN_INFO");
UserInfor userInfor = inforService.QueryInfor(userLoginInfo.getUserName());
System.out.println(userInfor.getName());
model.addAttribute("name",userInfor.getName());
model.addAttribute("username",userInfor.getUserName());
model.addAttribute("userid",userInfor.getId());
model.addAttribute("useremail",userInfor.getEmail());
model.addAttribute("address",userInfor.getAddress());
return "/WEB-INF/page/InformationStatistics/UserCenter.jsp";
}
@RequestMapping("/userupdate")
public String UserUpdate(Model model, HttpServletRequest req){
String name=req.getParameter("name");
int id= Integer.parseInt(req.getParameter("id"));
model.addAttribute("name",name);
model.addAttribute("id",id);
return "/WEB-INF/page/InformationStatistics/UserUpdatePage.jsp";
}
@RequestMapping("/pwdupdate")
public String PwdUpdate(HttpServletRequest req,HttpSession session){
String pwd= req.getParameter("pwd");
int id= Integer.parseInt(req.getParameter("id"));
inforService.UpdateInfor(pwd,id);
session.setAttribute("msg", "修改密码成功,将跳转登录界面");
return "redirect:/login";
}
@RequestMapping("/totalinfo")
public String TotalInfo(){
return "/WEB-INF/page/InformationStatistics/TotalBook.jsp";
}
@ResponseBody
@GetMapping("/pageNum/{pageNo}")
/**
* <h1>用户借阅/详情界面</h1>
*/
@Controller
@RequestMapping("/userBorrowing")
public class UserBorrowingController {
@Autowired
BookService bookService;
/*======================================书籍详情展示/用户借阅处理界面======================================*/
/**<h2>访问界面</h2>*/
@GetMapping
String userBorrowingPage(int bookId, Model model, HttpSession session, RedirectAttributes redirectAttributes){
//获取登录信息
UserLoginInfo userLoginInfo =(UserLoginInfo)session.getAttribute("USER_LOGIN_INFO");
Result result = bookPage(bookId, model);
result.addData(userLoginInfo);
model.addAttribute("result", result);
return "/WEB-INF/page/borrowingManagement/BookDetailsBorrowing.jsp";
}
@ResponseBody
@GetMapping("/{bookId}")
Result bookPage(@PathVariable int bookId, Model model){
Book book = bookService.getBookById(bookId);
return ResultFactory.getSucceedData(book);
}
/**
* <h2>获取总借阅量</h2>
*/
@ResponseBody
@GetMapping("/getBorrowingTotal/{bookId}")
Result getBorrowingTotal(@PathVariable int bookId){
int borrowingTotal = bookService.getBorrowingTotal(bookId);
Result result = ResultFactory.getSucceed();
result.addData("borrowingTotal",borrowingTotal);
return result;
}
/**
* <h2>近期借阅量</h2>
}
// 修改读者信息
@RequestMapping("/doUpdate")
public String doUpdate(User user1) {
readerService.updateUser(user1);
return "redirect:/reader/list";
}
@RequestMapping("/tiaozhuan")
String tiaozhuan(){
return "/WEB-INF/page/userManagement/User.jsp";
}
@Autowired
ReaderServices readerServices;
@PostMapping("/adduser")
String adduser(User user,RedirectAttributes redirectAttributes){
boolean i = readerServices.adduser(user);
if (i == false) {
redirectAttributes.addFlashAttribute("msg", "添加失败");
return "redirect:/ReaderController/jumpAdd";
} else {
redirectAttributes.addFlashAttribute("msg", "添加成功");
return "redirect:/ReaderController/tiaozhuan";
}
}
@PostMapping ("/deleteUser")
String deleteUser(int ids,RedirectAttributes redirectAttributes) {
System.out.println(ids);
int number = readerServices.deleteByIds(ids);
if (number == 0) {
redirectAttributes.addFlashAttribute("msg", "删除失败");
return "redirect:/reader/deleteUser";
} else {
redirectAttributes.addFlashAttribute("msg", "删除成功");
return "redirect:/reader/Page";
}
}
@RequestMapping("/Page")
String Page()
@Controller
@RequestMapping("/borrowingRecords")
public class RecordsBorrowingController {
/**<h2>页面访问</h2>*/
@RequestMapping("/page")
String borrowingRecords(){
return "/WEB-INF/page/borrowingManagement/BorrowingRecords.jsp";
}
@Autowired
BorrowingServices borrowingServices;
/**
* <h2>获取借书记录</h2>
*/
@ResponseBody
@GetMapping("/{userId}")
Result borrowingRecords( @PathVariable int userId){
Result succeed = ResultFactory.getSucceed();
List<UserBorrowingInfo> userBorrowingInfoList = borrowingServices.getUserBorrowingInfoByUserId(userId);
succeed.addData("userBorrowingInfoList",userBorrowingInfoList);
return succeed;
}
/**
* <h2>还书请求处理方法</h2>
*/
@PostMapping ("/returnBook")
@ResponseBody
Result returnBook(int borrowingId,int isReturn,boolean isTimeout){
String s = null;
try {
s = borrowingServices.returnBook(borrowingId, isReturn, isTimeout);
} catch (Exception e) {
return ResultFactory.getFail(e.getMessage());
}
return ResultFactory.getSucceed(s);
}
/**
* <h2>取消预约方法</h2>
*/
@ResponseBody
System.out.println(ids);
int number = bookManService.deleteByIds(ids);
if (number == -1) {
redirectAttributes.addFlashAttribute("msg", "删除失败");
return "redirect:/searchcontroller/deleteBook";
} else {
redirectAttributes.addFlashAttribute("msg", "删除成功");
return "redirect:/searchcontroller/page";
}
}
@ResponseBody
@RequestMapping ("/queryBook")
public List<Book> queryBook(String keyword) {
return bookManService.queryBook(keyword);
}
@RequestMapping("/test")
public String Test(){return "/WEB-INF/page/bookManagement/test.jsp";}
@RequestMapping("/UpdateBook")
public String UpdateBook(Book book,Model model) {
// 更新图书信息
// try {
bookManService.bookUpdate(book);
// } catch (Exception e) {
// model.addAttribute("msg",e);
// return "redirect:/searchcontroller/UpdateDate/"+book.getBookId();
// }
model.addAttribute("msg","图书修改成功!");
return "redirect:/searchcontroller/bookUpdate";
}
}
* <h2>接收访问请求</h2>
* 将普通用户与管理员区分;将用户信息发送给前端页面;
*/
@GetMapping
String borrowingPage(HttpSession session, Model model){
return "forward:/borrowing/userBorrowing";
}
// @GetMapping("/rootBorrowing")
// String rootBorrowingPage() {
// return "/WEB-INF/page/borrowingManagement/RootBorrowing.jsp";
// }
@GetMapping("/userBorrowing")
String userBorrowingPage() {
return "/WEB-INF/page/borrowingManagement/UserBorrowing.jsp";
}
/**
* <h2>分页查询</h2>
*/
@ResponseBody
@GetMapping("/getBookListPage/{pageNo}")
Page<BookInformation> getBookListPage(@PathVariable int pageNo){
return bookService.getBookInformationPage(pageNo, 6);
}
@ResponseBody
@PostMapping("/search/{pageNo}")
Page<BookInformation> search(@RequestBody BookCondition bookCondition,@PathVariable int pageNo){
return bookService.getBookInformationByCondition(bookCondition,pageNo,6);
}
@ResponseBody
@GetMapping("/getBookType")
List<String> getBookType(){
return bookService.getBookTypeAll();
}
}