基于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
}
// @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();
}
}
/**
* <h1>登录拦截器</h1>
* 限制用户,不登陆无法访问的页面
*/
public List<User> list() {
return readerService.getAllName();
}
// 跳转到页面
@RequestMapping("/toadd")
public String toAdd() {
return "/WEB-INF/page/userManagement/User.jsp";
}
@RequestMapping("/jumpAdd")
String jumpAdd(RedirectAttributes redirectAttributes, Model model){
model.addAttribute("msg", redirectAttributes.getAttribute("msg"));
return "/WEB-INF/page/userManagement/adduser.jsp";
}
// 新增读者
@ResponseBody
@RequestMapping("/doAdd")
public String doAdd(User user){
if (readerService.adduser(user)){
return "success";
}
return "falue";
}
@RequestMapping("/Deleteuser")
String Deleteuser(){
return "/WEB-INF/page/userManagement/Deleteuser.jsp";
}
// 删除读者信息
@RequestMapping("/delete/{UserId}")
public String delete(@PathVariable("UserId") Integer UserId) {
readerService.deleteUser(UserId);
return "redirect:/reader/list";
}
@RequestMapping("/Searchuser")
String Searchuser(){
return "/WEB-INF/page/userManagement/Searchuser.jsp";
}
@ResponseBody
@RequestMapping ("/userSearch")
public List<User> queryBook(String keyword) {
return readerService.queryuser(keyword);
@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>
*/
@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);
}
@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);}
}
/**
* 对于管理员账号登录后进行的操作
*
*/
@Controller
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);
}
catch (Exception e){
isBorrowingSucceed=false;
message=e.getMessage();
}
if(isBorrowingSucceed){
Result succeed = ResultFactory.getSucceed();
succeed.addData("isBorrowingSucceed",isBorrowingSucceed);
return succeed;
}else{
return ResultFactory.getFail(message);
}
}
}
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));
}
}
* */
@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>
* */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
UserLoginInfo userLoginInfo =(UserLoginInfo)request.getSession().getAttribute("USER_LOGIN_INFO");
//若登录信息为空,即 用户未登录,类别不为零则 非管理员
if(userLoginInfo == null||userLoginInfo.getType()!=0){
// 删除读者信息
@RequestMapping("/delete/{UserId}")
public String delete(@PathVariable("UserId") Integer UserId) {
readerService.deleteUser(UserId);
return "redirect:/reader/list";
}
@RequestMapping("/Searchuser")
String Searchuser(){
return "/WEB-INF/page/userManagement/Searchuser.jsp";
}
@ResponseBody
@RequestMapping ("/userSearch")
public List<User> queryBook(String keyword) {
return readerService.queryuser(keyword);
}
// 跳转到修改读者信息页面
@RequestMapping("/toUpdate/{readerId}")
public String toUpdate(@PathVariable("readerId") Integer readerId, Model model) {
User user2 = readerService.getReaderById(readerId);
model.addAttribute("reader", user2);
return "reader/update";
}
// 修改读者信息
@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 {
}
/**
* <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";
}
public class SearchController {
@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";
{
return "/WEB-INF/page/userManagement/User.jsp";
}
@ResponseBody
@RequestMapping("/queryuser")
public List<User> queryuser(String keywords){
return readerService.queryuser(keywords);
}
}
/**
* <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>
/**
* <h1>登录信息拦截器</h1>
* 将Session添加到request中
*/
@Component
public class LoginInfoInterceptor implements HandlerInterceptor {
/**
* <h2>前置处理</h2>
* 如果Session中有用户登录信息,则将其发给请求域
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//设置字符集
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession();
Boolean isFirstVisit = (Boolean) session.getAttribute("isFirstVisit");
if (isFirstVisit == null || isFirstVisit) {// 第一次加载
//消息处理
String msg = request.getParameter("msg");
if(!StringDispose.isNotNull(msg)){
/*HttpSession */session = request.getSession(false);//参数 false 表示不创建新的 session
if (session!= null) {
msg = (String) session.getAttribute("msg");
if(StringDispose.isNotNull(msg))session.setAttribute("msg",null);
}
if(StringDispose.isNotNull(msg)) {
PrintWriter out = response.getWriter();
out.flush();
//out.close();
}
}
}
//登录信息处理
Object userLoginInfo = request.getSession().getAttribute("USER_LOGIN_INFO");
//将信息发送到请求域
if(userLoginInfo!=null) request.setAttribute("userLoginInfo",userLoginInfo);
return HandlerInterceptor.super.preHandle(request, response, handler);
}
}
@RequestMapping("/typepageNum/{pageNo}")
public Page<Map<String,Object>> TypeInfor(@PathVariable int pageNo){return toTalInfor.ReceiveByType(pageNo,5);}
}
/**
* 对于管理员账号登录后进行的操作
*
*/
@Controller
@RequestMapping("/reader")
public class ReaderController {
UserMapper userMapper;
@Autowired
private ReaderServices readerService;
// 查询所有读者信息
@RequestMapping("/list")
@ResponseBody()
public List<User> list() {
return readerService.getAllName();
}
// 跳转到页面
@RequestMapping("/toadd")
public String toAdd() {
return "/WEB-INF/page/userManagement/User.jsp";
}
@RequestMapping("/jumpAdd")
String jumpAdd(RedirectAttributes redirectAttributes, Model model){
model.addAttribute("msg", redirectAttributes.getAttribute("msg"));
return "/WEB-INF/page/userManagement/adduser.jsp";
}
// 新增读者
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>
*/
@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;
}
/**
* 借阅数量
/**
* <h1>管理员拦截器</h1>
* 限制用户,只有管理员可以访问
*/
@Component
public class RootInterceptor implements HandlerInterceptor {
/**
* <h2>前置处理</h2>
* */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
UserLoginInfo userLoginInfo =(UserLoginInfo)request.getSession().getAttribute("USER_LOGIN_INFO");
//若登录信息为空,即 用户未登录,类别不为零则 非管理员
if(userLoginInfo == null||userLoginInfo.getType()!=0){
//无权限则返回主页
response.sendRedirect("/main"+"?msg="+ URLEncoder.encode("只有管理员才可以访问", "UTF-8"));//重定向到上一个页面
return false;
}
return HandlerInterceptor.super.preHandle(request, response, handler);
}
}
* 将Session添加到request中
*/
@Component
public class LoginInfoInterceptor implements HandlerInterceptor {
/**
* <h2>前置处理</h2>
* 如果Session中有用户登录信息,则将其发给请求域
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//设置字符集
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession();
Boolean isFirstVisit = (Boolean) session.getAttribute("isFirstVisit");
if (isFirstVisit == null || isFirstVisit) {// 第一次加载
//消息处理
String msg = request.getParameter("msg");
if(!StringDispose.isNotNull(msg)){
/*HttpSession */session = request.getSession(false);//参数 false 表示不创建新的 session
if (session!= null) {
msg = (String) session.getAttribute("msg");
if(StringDispose.isNotNull(msg))session.setAttribute("msg",null);
}
if(StringDispose.isNotNull(msg)) {
PrintWriter out = response.getWriter();
out.flush();
//out.close();
}
}
}
//登录信息处理
Object userLoginInfo = request.getSession().getAttribute("USER_LOGIN_INFO");
//将信息发送到请求域
if(userLoginInfo!=null) request.setAttribute("userLoginInfo",userLoginInfo);
return HandlerInterceptor.super.preHandle(request, response, handler);
}
}