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

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

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

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

项目介绍

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

借阅管理,图书检索,查看借还记录,查看图书详情,还书管理,登录页面等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;

5.数据库:MySql 5.7版本;

6.是否Maven项目:是;

技术栈

  1. 后端:SpringBoot

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

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入localhost:8083/ 登录

public class LoginInterceptor implements HandlerInterceptor {
    @Resource
    private UserService userService;

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws Exception {

        // 如果不是映射到方法直接通过
        if (!(object instanceof HandlerMethod)) {
            return true;
        }
        HandlerMethod handlerMethod = (HandlerMethod) object;
        Method method = handlerMethod.getMethod();
        //检查是否有passtoken注解,有则跳过认证
        if (method.isAnnotationPresent(PassToken.class)) {
            PassToken passToken = method.getAnnotation(PassToken.class);
            if (passToken.required()) {
                return true;
            }
        }
        //检查有没有需要用户登录的注解
        User currentUser = (User) httpServletRequest.getSession().getAttribute("user");
        if (method.isAnnotationPresent(LoginRequired.class)) {
            LoginRequired loginRequired = method.getAnnotation(LoginRequired.class);
            if (loginRequired.required()) {
                if (currentUser == null) {
                    httpServletResponse.sendRedirect("/login.jsp");
                    return false;
                }
            }
        }
        //检查有没有需要用户token的注解
        String token = httpServletRequest.getHeader("token");// 从 http 请求头中取出 token
        if (method.isAnnotationPresent(UserLoginToken.class)) {
            UserLoginToken userLoginToken = method.getAnnotation(UserLoginToken.class);
            if (userLoginToken.required()) {
                // 执行认证
                if (token == null) {
                    throw new RuntimeException("token为空,请重新登录");
                }
    @LoginRequired
    public JsonData userInfo(Long userId) {
        User user = userService.findUserByUserId(userId);
        user.setUserPassword(null);
        return JsonData.success(user);
    }

    @PostMapping("/userInfoHis")
    @LoginRequired
    public JsonData userInfoHis(Long userId) {
        User user = userService.findUserByUserId(userId);
        user.setUserPassword(null);
        return JsonData.success(user);
    }
}

/**
 * @Auther: admin
 * @Description: BookInfoController
 */
@RestController
@RequestMapping("/bookinfo")
public class BookInfoController {

    @Resource
    private BookInfoService bookInfoService;

    @Resource
    private BookTypeService bookTypeService;

    /**
     * @param bookInfo
    @Resource
    private LendBookService lendBookService;

    @Resource
    private BookInfoService bookInfoService;

    @Resource
    private UserService userService;

    @PostMapping("/lendBook")
    @LoginRequired
    public JsonData lendBook(LendReturnList lendReturnList) throws ParseException {
        User user = userService.findUserByUserId(lendReturnList.getUserId());
        if (user == null) {
            return JsonData.fail("用户不存在");
        }
        if (user.getUserState() == 0) {
            return JsonData.fail("用户已被禁用,无法借阅");
        }
        BookInfo info = bookInfoService.selectBookInfoById(lendReturnList.getBookId());
        if (info == null) {
            return JsonData.fail("图书不存在");
        }
        if (info.getBookState() == 1) {
            return JsonData.fail("图书已被借出,无法借阅");
        }
        int i = lendBookService.lendBook(lendReturnList);
        //更新图书状态为借出
        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("借阅失败");
        }

    }

     * @description: 应用列表(easyui tree grid)
     */
    @PostMapping("/list")
    @LoginRequired
    public DataGridDataSource<Permission> list() {

        List<Permission> permissionTreeGridList = new ArrayList<>();
        List<Permission> permissionList = permissionService.queryAll();
        for (Permission permission : permissionList) {
            Permission permissionTreeGrid = new Permission();
            permissionTreeGrid.setPermissionId(permission.getPermissionId());
            permissionTreeGrid.setPermissionName(permission.getPermissionName());
            permissionTreeGrid.setPermissionUrl(permission.getPermissionUrl());
            permissionTreeGrid.setPermissionIcon(permission.getPermissionIcon());
            permissionTreeGrid.setPermissionCreateTime(permission.getPermissionCreateTime());
            permissionTreeGrid.setPermissionLastModifyTime(permission.getPermissionLastModifyTime());
            permissionTreeGrid.set_parentId(permission.getPermissionParentId());
            permissionTreeGridList.add(permissionTreeGrid);
        }
        DataGridDataSource<Permission> permissionDataGridDataSource = new DataGridDataSource<>();
        permissionDataGridDataSource.setTotal(permissionTreeGridList.size());
        permissionDataGridDataSource.setRows(permissionTreeGridList);
        return permissionDataGridDataSource;
    }
}

/**
 * @Auther: admin
 * @Description:
 */
@RestController
@RequestMapping("/book")
public class ReturnBookController {

    @Resource

/**
 * @Auther: admin
 * @Description: LendBookController
 */
@RestController
@RequestMapping("/book")
public class LendBookController {

    @Resource
    private LendBookService lendBookService;

    @Resource
    private BookInfoService bookInfoService;

    @Resource
    private UserService userService;

    @PostMapping("/lendBook")
    @LoginRequired
    public JsonData lendBook(LendReturnList lendReturnList) throws ParseException {
        User user = userService.findUserByUserId(lendReturnList.getUserId());
        if (user == null) {
            return JsonData.fail("用户不存在");
        }
        if (user.getUserState() == 0) {
            return JsonData.fail("用户已被禁用,无法借阅");
        }
        BookInfo info = bookInfoService.selectBookInfoById(lendReturnList.getBookId());
        if (info == null) {
            return JsonData.fail("图书不存在");
        }
        if (info.getBookState() == 1) {
            return JsonData.fail("图书已被借出,无法借阅");
        }
        int i = lendBookService.lendBook(lendReturnList);
        //更新图书状态为借出
        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("借阅失败");
 * @Description: UserController
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @Resource
    private RoleService roleService;

    @Resource
    private PermissionService permissionService;

    @Resource
    private MailService mailService;

    @Resource
    private VaptchaCheckService vaptchaCheckService;

    /**
     * @param userName
     * @param userPassword
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 用户登录
     */
    @PostMapping("/login")
    public JsonData login(@RequestParam(value = "userName") String userName,
                          @RequestParam(value = "userPassword") String userPassword,
                          @RequestParam(value = "vaptchaToken") String vaptchaToken,
                          HttpServletRequest request,
                          HttpSession session) throws Exception {

        if (StringUtils.isEmpty(userName)) {
            return JsonData.fail("用户名不能为空!");
        }
        if (StringUtils.isEmpty(userPassword)) {
            return JsonData.fail("密码不能为空!");
        }
//        if (StringUtils.isEmpty(vaptchaToken)) {
//            return JsonData.fail("请进行人机验证!");
//        }
        User user = userService.findUserByUserName(userName);
        if (user == null) {
            return JsonData.fail("用户不存在!");
        }
        if (user.getUserState() == 0) {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}

/**
 * @Auther: admin
 * @Description: 文件上传Controller
 */
@Controller
public class UploadController {

    @Value(value = "${upload.file.path}")
    private String uploadFilePath;

    /**
     * @param file
     * @return : java.util.Map<java.lang.String,java.lang.Object>
     * @description: 根据id删除分类
     */
    @DeleteMapping("/delete")
    @LoginRequired
    public JsonData deleteBookType(@RequestParam(value = "bookTypeId") Integer bookTypeId) {

        int count = bookTypeService.deleteBookType(bookTypeId);
        if (count > 0) {
            return JsonData.success(count, "删除成功");
        } else {
            return JsonData.fail("删除失败");
        }
    }

    /**
     * @param bookType
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 新增分类
     */
    @PostMapping("/save")
    @LoginRequired
    public JsonData saveBookType(BookType bookType) {
        int count = bookTypeService.saveBookType(bookType);
        if (count > 0) {
            return JsonData.success(count, "新增成功");
        } else {
            return JsonData.fail("新增失败");
        }
    }

    /**
     * @param bookType
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 修改分类
     */
    @PutMapping("/update")
    @LoginRequired
    public JsonData update(BookType bookType) {
        int count = bookTypeService.updateBookType(bookType);
        if (count > 0) {
            return JsonData.success(count, "修改成功");
        } else {
            return JsonData.fail("修改失败");
        }
    }
}
            if (authUriSet.contains(uri)) {
                return true;
            } else {
                response.sendRedirect("/403.jsp");
                return false;
            }
        } else {
            return true;
        }
    }

    /**
     * Intercept the execution of a handler. Called after HandlerAdapter actually
     * invoked the handler, but before the DispatcherServlet renders the view.
     * Can expose additional model objects to the view via the given ModelAndView.
     * <p>DispatcherServlet processes a handler in an execution chain, consisting
     * of any number of interceptors, with the handler itself at the end.
     * With this method, each interceptor can post-process an execution,
     * getting applied in inverse order of the execution chain.
     * <p><strong>Note:</strong> special considerations apply for asynchronous
     * request processing. For more details see
     * {@link AsyncHandlerInterceptor}.
     *
     * @param request      current HTTP request
     * @param response     current HTTP response
     * @param handler      handler (or {@link HandlerMethod}) that started asynchronous
     *                     execution, for type and/or instance examination
     * @param modelAndView the {@code ModelAndView} that the handler returned
     *                     (can also be {@code null})
     * @throws Exception in case of errors
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    /**
     * Callback after completion of request processing, that is, after rendering
     * the view. Will be called on any outcome of handler execution, thus allows
     * for proper resource cleanup.
     * <p>Note: Will only be called if this interceptor's {@code preHandle}
     * method has successfully completed and returned {@code true}!
     * <p>As with the {@code postHandle} method, the method will be invoked on each
     * interceptor in the chain in reverse order, so the first interceptor will be
     * the last to be invoked.
     * <p><strong>Note:</strong> special considerations apply for asynchronous
     * request processing. For more details see
     * {@link AsyncHandlerInterceptor}.
     *
     * @param request  current HTTP request
     * @param response current HTTP response
     * @param handler  handler (or {@link HandlerMethod}) that started asynchronous
        return bookTypes;
    }

    /**
     * @param bookTypeId
     * @return : io.hailiang.web.book.common.DataGridDataSource<io.hailiang.web.book.model.BookType>
     * @description: 根据id查询分类列表
     */
    @PostMapping("/listByBookTypeId")
    @LoginRequired
    public DataGridDataSource<BookType> selectBookTypeListByBookTypeId(@RequestParam(defaultValue = "0") Integer bookTypeId) {

        List<BookType> bookTypeList = bookTypeService.selectBookTypeListByBookTypeId(bookTypeId);
        DataGridDataSource<BookType> dataGridDataSource = new DataGridDataSource<>();
        dataGridDataSource.setRows(bookTypeList);
        dataGridDataSource.setTotal(bookTypeList.size());
        return dataGridDataSource;
    }

    /**
     * @param bookTypeId
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 根据id删除分类
     */
    @DeleteMapping("/delete")
    @LoginRequired
    public JsonData deleteBookType(@RequestParam(value = "bookTypeId") Integer bookTypeId) {

        int count = bookTypeService.deleteBookType(bookTypeId);
        if (count > 0) {
            return JsonData.success(count, "删除成功");
        } else {
            return JsonData.fail("删除失败");
        }
    }

    /**
     * @param bookType
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 修改分类
     */
    @PutMapping("/update")
    @LoginRequired
    public JsonData update(BookType bookType) {
        int count = bookTypeService.updateBookType(bookType);
        if (count > 0) {
            return JsonData.success(count, "修改成功");
        } else {
            return JsonData.fail("修改失败");
        }
    }
}

public class LoginInterceptor implements HandlerInterceptor {
    @Resource
    private UserService userService;

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws Exception {


/**
 * @Auther: admin
 * @Description: BookInfoController
 */
@RestController
@RequestMapping("/bookinfo")
public class BookInfoController {

    @Resource
    private BookInfoService bookInfoService;

    @Resource
    private BookTypeService bookTypeService;

    /**
     * @param bookInfo
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 新增图书
     */
    @PostMapping("/save")
    @LoginRequired
    public JsonData saveBookInfo(BookInfo bookInfo) {
        int count = bookInfoService.saveBookInfo(bookInfo);
        if (count > 0) {
            return JsonData.success(count, "新增成功");
        } else {
            return JsonData.fail("新增失败");
        }
    }

    /**
     * @param bookInfo
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 编辑图书
     */
        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));

        //回显
        StringBuffer sb = new StringBuffer();
        sb.append("<script type=\"text/javascript\">");
        sb.append("window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ",'" + "/uploads/" + new SimpleDateFormat("yyyy/MM/dd").format(date) + "/" + dir1 + "/" + dir2 + "/" + newFileName + "','')");
        sb.append("</script>");
        return sb.toString();
    }
}

/**
 * @Auther: admin
 * @Description:
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    /**
     * @param roleId
     * @return : java.lang.Object
    @LoginRequired
    public JsonData updateBookInfo(BookInfo bookInfo) {
        int count = bookInfoService.updateBookInfo(bookInfo);
        if (count > 0) {
            return JsonData.success(count, "编辑成功");
        } else {
            return JsonData.fail("编辑失败");
        }
    }

    /**
     * @param bookId
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 根据id删除图书
     */
    @DeleteMapping("/delete")
    @LoginRequired
    public JsonData deleteBookInfo(Integer bookId) {
        int count = bookInfoService.deleteBookInfo(bookId);
        if (count > 0) {
            return JsonData.success(count, "删除成功");
        } else {
            return JsonData.fail("删除失败");
        }
    }

    /**
     * @param page
     * @param rows
     * @return : io.hailiang.web.book.common.DataGridDataSource<io.hailiang.web.book.model.BookInfo>
     * @description: 图书列表
     */
    @PostMapping("/list")
    @LoginRequired
    public DataGridDataSource<BookInfo> bookInfoList(@RequestParam(value = "bookIsbn", required = false, defaultValue = "") String bookIsbn,
                                                     @RequestParam(value = "bookName", required = false, defaultValue = "") String bookName,
                                                     @RequestParam(value = "bookAuthor", required = false, defaultValue = "") String bookAuthor,
                                                     @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                                     @RequestParam(value = "rows", required = false, defaultValue = "10") Integer rows) {
        PageBean pageBean = new PageBean(page, rows);
        Map<String, Object> map = new HashMap<>();
        map.put("start", pageBean.getStart());
        map.put("size", pageBean.getPageSize());
        map.put("bookIsbn", "%" + bookIsbn + "%");
        map.put("bookName", "%" + bookName + "%");
        map.put("bookAuthor", "%" + bookAuthor + "%");
        List<BookInfo> bookInfoList = bookInfoService.selectBookInfoList(map);

/**
 * @Auther: admin
 * @Description: BookInfoController
 */
@RestController
@RequestMapping("/bookinfo")
public class BookInfoController {

    @Resource
    private BookInfoService bookInfoService;

    @Resource
    private BookTypeService bookTypeService;

    /**
     * @param bookInfo
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 新增图书
     */
    @PostMapping("/save")
    @LoginRequired
    public JsonData saveBookInfo(BookInfo bookInfo) {
        int count = bookInfoService.saveBookInfo(bookInfo);
        if (count > 0) {
            return JsonData.success(count, "新增成功");
        } else {
            return JsonData.fail("新增失败");
        }
    }


/**
 * @Auther: admin
 * @Description: LendBookController
 */
@RestController
@RequestMapping("/book")
public class LendBookController {

    @Resource
    private LendBookService lendBookService;

    @Resource
    private BookInfoService bookInfoService;

    @Resource
    private UserService userService;

    @PostMapping("/lendBook")
    @LoginRequired
    public JsonData lendBook(LendReturnList lendReturnList) throws ParseException {
        User user = userService.findUserByUserId(lendReturnList.getUserId());
        if (user == null) {
            return JsonData.fail("用户不存在");
        }
        if (user.getUserState() == 0) {
            return JsonData.fail("用户已被禁用,无法借阅");
        }
        DataGridDataSource<User> dataGridDataSource = new DataGridDataSource<>();
        dataGridDataSource.setTotal(totalUser);
        dataGridDataSource.setRows(userList);
        return dataGridDataSource;
    }

    /**
     * @param userId
     * @param roleIds
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 用户角色设置(先删除当前用户拥有的角色关系, 再重新设置)
     */
    @PostMapping("/saveRoleSet")
    @LoginRequired
    public JsonData saveRoleSet(Long userId, Integer[] roleIds) {
        //先删除当前用户拥有的角色关系
        roleService.deleteRoleUserRsByUserId(userId);
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("roleIds", roleIds);
        int count = userService.insertUserRoles(map);
        if (count > 0) {
            return JsonData.success(count, "设置成功");
        } else {
            return JsonData.fail("设置失败");
        }
    }

    /**
     * @param oldPassword
     * @param newPassword
     * @param session
     * @return : io.hailiang.web.book.common.JsonData
     * @description: 修改密码
     */
    @PostMapping("/modifyPassword")
    @LoginRequired
    public JsonData modifyPassword(String oldPassword, String newPassword, HttpSession session) {

        User currentUser = (User) session.getAttribute("user");
        User user = userService.findUserByUserId(currentUser.getUserId());
        if (!Md5Util.md5(oldPassword, Md5Util.SALT).equals(user.getUserPassword())) {
            return JsonData.fail("原密码错误");
        }
        user.setUserPassword(newPassword);
        int i = userService.updateUser(user);
        if (i > 0) {
            return JsonData.success(i, "修改成功");

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值