图书借阅管理系统java+SpringBoot+Mybatis+Html+maven+Mysql

       管理员和读者角色功能有:图书管理、借阅管理、读者管理。


       页面使用的是原生的Jquery,没有使用到Thymeleaf模板引擎,如果想学习的话可以下载下来,可以继续在上面加功能,比如班级管理、学生管理、学院管理、图书馆管理、借阅图书报表等功能。


       运行环境:jdk1.8、mysql5.x、maven3.5\3.6、idea\eclipse。


图书借阅管理系统1.jpg









 

       用户管理控制层:

    /**
     * @Description 用户管理
     */
    @Api(tags = "用户管理")
    @RestController
    @RequestMapping("/user")
    public class UsersController {
     
        @Autowired
        private UserService userService;
     
        @ApiOperation("用户列表")
        @PostMapping("/list")
        public R getUsers(@RequestBody PageIn pageIn) {
            if (pageIn == null) {
                return R.fail(CodeEnum.PARAM_ERROR);
            }
            // 封装分页出参对象
            PageInfo<Users> userList = userService.getUserList(pageIn);
            PageOut pageOut = new PageOut();
            pageOut.setCurrPage(userList.getPageNum());
            pageOut.setPageSize(userList.getPageSize());
            pageOut.setTotal((int) userList.getTotal());
            List<UserOut> outs = new ArrayList<>();
            for (Users users : userList.getList()) {
                UserOut out = new UserOut();
                BeanUtils.copyProperties(users,out);
                out.setIdent(ConvertUtil.identStr(users.getIdentity()));
                out.setBirth(DateUtil.format(users.getBirthday(),Constants.DATE_FORMAT));
                outs.add(out);
            }
            pageOut.setList(outs);
            return R.success(CodeEnum.SUCCESS,pageOut);
        }
     
     
        /**
         * 添加读者操作
         * @param users
         * @return
         */
        @ApiOperation("添加读者")
        @ResponseBody
        @PostMapping("/addReader")
        public R addReader(Users users) {
            if (users == null) {
                return R.fail(CodeEnum.PARAM_ERROR);
            }
            if(StringUtils.isEmpty(users.getAvatar())) {
                return R.fail(CodeEnum.USER_HEAD_PIC_ERROR);
            }
            if(StringUtils.isEmpty(users.getUsername())) {
                return R.fail(CodeEnum.USERNAME_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(users.getNickname())) {
                return R.fail(CodeEnum.NICKNAME_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(users.getTel())) {
                return R.fail(CodeEnum.USER_MOBILE_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(users.getEmail())) {
                return R.fail(CodeEnum.USER_EMAIL_NOT_EXIST_ERROR);
            }
            Users byUsername = userService.findByUsername(users.getUsername());
            if(byUsername!=null){
                return R.fail(CodeEnum.USER_NAME_IS_EXIST_ERROR);
            }
            // 读者默认是普通用户
            users.setIsAdmin(1);
            Users users1 = userService.addUser(users);
            if(users1==null){
                return R.fail(CodeEnum.USER_ADD_ERROR);
            }
            return R.success(CodeEnum.SUCCESS);
        }
     
     
        /**
         * 编辑用户操作
         * @param users
         * @return
         */
        @ApiOperation("编辑用户")
        @ResponseBody
        @PostMapping("/edit")
        public R modifyUsers(Users users) {
            if (users == null) {
                return R.fail(CodeEnum.PARAM_ERROR);
            }
            if(StringUtils.isEmpty(users.getAvatar())) {
                return R.fail(CodeEnum.USER_HEAD_PIC_ERROR);
            }
            if(StringUtils.isEmpty(users.getUsername())) {
                return R.fail(CodeEnum.USERNAME_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(users.getNickname())) {
                return R.fail(CodeEnum.NICKNAME_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(users.getTel())) {
                return R.fail(CodeEnum.USER_MOBILE_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(users.getEmail())) {
                return R.fail(CodeEnum.USER_EMAIL_NOT_EXIST_ERROR);
            }
            Users byUsername = userService.findByUsername(users.getUsername());
            if(byUsername!=null){
                if(!byUsername.getId().equals(users.getId())){
                    return R.fail(CodeEnum.USER_NAME_IS_EXIST_ERROR);
                }
            }
            if(!userService.updateUser(users)){
                return R.fail(CodeEnum.USER_EDIT_ERROR);
            }
            return R.success(CodeEnum.SUCCESS);
        }
     
     
        @ApiOperation("用户详情")
        @GetMapping("/detail")
        public R userDetail(Integer id) {
            Users user = userService.findUserById(id);
            if (user!=null) {
                UserOut out = new UserOut();
                BeanUtils.copyProperties(user,out);
                out.setBirth(DateUtil.format(user.getBirthday(),Constants.DATE_FORMAT));
                out.setIdent(ConvertUtil.identStr(user.getIdentity()));
                return R.success(CodeEnum.SUCCESS,out);
            }
     
            return R.fail(CodeEnum.NOT_FOUND);
        }
     
        @ApiOperation("删除用户")
        @GetMapping("/delete")
        public R delUsers(Integer id) {
            userService.deleteUser(id);
            return R.success(CodeEnum.SUCCESS);
        }
     
        @ApiOperation("获取当前用户登陆信息")
        @GetMapping("/currUser")
        public R getCurrUser() {
            Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            if (principal!=null) {
                Map<String,Object> map = BeanUtil.beanToMap(principal);
                String username = (String) map.get("username");
                if (StrUtil.isNotBlank(username)) {
                    Users users = userService.findByUsername(username);
                    UserOut out = new UserOut();
                    BeanUtils.copyProperties(users,out);
                    out.setBirth(DateUtil.format(users.getBirthday(),Constants.DATE_FORMAT));
                    Integer identity = users.getIdentity();
                    String ident = "";
                    if (identity == Constants.STUDENT) {
                        ident = Constants.STU_STR;
                    }else if (identity == Constants.TEACHER) {
                        ident = Constants.TEA_STR;
                    }else if (identity == Constants.OTHER) {
                        ident = Constants.OTHER_STR;
                    }else if (identity == Constants.ADMIN) {
                        ident = Constants.ADMIN_STR;
                    }
                    out.setIdent(ident);
                    return R.success(CodeEnum.SUCCESS,out);
                }
            }
            return R.fail(CodeEnum.USER_NOT_FOUND);
        }
    }



     登录控制层:



    @Controller
    public class LoginController {
     
        @Autowired
        private UserService userService;
     
        /**
         * 登录, 使用SpringSecurity 无需自己编写登录接口
         */
    //    @ResponseBody
    //    @RequestMapping(method = RequestMethod.POST,value = "/user/login")
    //    public R login(HttpServletRequest request, HttpServletResponse response) throws IOException {
    //        String username = request.getParameter("username");
    //        String password = request.getParameter("password");
    //
    //        if (StrUtil.isNotBlank(username)&&StrUtil.isNotBlank(password)) {
    //            Users users = userService. login(username, password);
    //            if (users!=null) {
    //                request.getSession().setAttribute("username",username);
    //                return R.success(CodeEnum.SUCCESS);
    //            }
    //        }
    //
    //        return R.fail(CodeEnum.NAME_OR_PASS_ERROR);
    //    }
    }



    图书管理控制层:



    @Api(tags = "图书管理")
    @RestController
    @RequestMapping("/book")
    public class BookController {
     
        @Autowired
        private BookService bookService;
     
        @ApiOperation("图书搜索列表")
        @PostMapping("/list")
        public R getBookList(@RequestBody PageIn pageIn) {
            if (pageIn == null) {
                return R.fail(CodeEnum.PARAM_ERROR);
            }
            return R.success(CodeEnum.SUCCESS,bookService.getBookList(pageIn));
        }
     
        /**
         * 添加图片操作
         * @param book
         * @return
         */
        @ApiOperation("添加图书")
        @ResponseBody
        @PostMapping("/add")
        public R addBook(Book book) {
            if(StringUtils.isEmpty(book.getName())){
                return R.fail(CodeEnum.BOOK_NAME_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(book.getIsbn())){
                return R.fail(CodeEnum.BOOK_ISBN_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(book.getPic())){
                return R.fail(CodeEnum.BOOK_IMAGE_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(book.getAuthor())){
                return R.fail(CodeEnum.BOOK_AUTHOR_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(book.getType())){
                return R.fail(CodeEnum.BOOK_TYPE_NOT_EXIST_ERROR);
            }
            BookOut bookByIsbn = bookService.findBookByIsbn(book.getIsbn());
            if(bookByIsbn.getName()!=null){
                return R.fail(CodeEnum.BOOK_ISBN_EXIST_ERROR);
            }
            if(bookService.addBook(book)==null){
                return R.fail(CodeEnum.BOOK_ADD_ERROR);
            }
            return R.success(CodeEnum.SUCCESS);
        }
     
        /**
         * 编辑图书
         * @param book
         * @return
         */
        @ApiOperation("编辑图书")
        @ResponseBody
        @PostMapping("/edit")
        public R editBook(Book book) {
            if(StringUtils.isEmpty(book.getName())){
                return R.fail(CodeEnum.BOOK_NAME_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(book.getIsbn())){
                return R.fail(CodeEnum.BOOK_ISBN_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(book.getPic())){
                return R.fail(CodeEnum.BOOK_IMAGE_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(book.getAuthor())){
                return R.fail(CodeEnum.BOOK_AUTHOR_NOT_EXIST_ERROR);
            }
            if(StringUtils.isEmpty(book.getType())){
                return R.fail(CodeEnum.BOOK_TYPE_NOT_EXIST_ERROR);
            }
            BookOut bookByIsbn = bookService.findBookByIsbn(book.getIsbn());
            if(bookByIsbn.getName()!=null){
                if(!bookByIsbn.getId().equals(book.getId())){
                    return R.fail(CodeEnum.BOOK_ISBN_EXIST_ERROR);
                }
            }
            if(!bookService.updateBook(book)){
                return R.fail(CodeEnum.BOOK_EDIT_ERROR);
            }
            return R.success(CodeEnum.SUCCESS);
        }
     
     
        @ApiOperation("图书详情")
        @GetMapping("/detail")
        public R bookDetail(Integer id) {
            return R.success(CodeEnum.SUCCESS,bookService.findBookById(id));
        }
     
        @ApiOperation("图书详情 根据ISBN获取")
        @GetMapping("/detailByIsbn")
        public R bookDetailByIsbn(String isbn) {
            BookOut bookByIsbn = bookService.findBookByIsbn(isbn);
            if(bookByIsbn.getId()==null){
                return R.fail(CodeEnum.BOOK_NOT_EXIST_ERROR);
            }
            return R.success(CodeEnum.SUCCESS,bookByIsbn);
        }
     
        @ApiOperation("删除图书")
        @GetMapping("/delete")
        public R delBook(Integer id) {
            bookService.deleteBook(id);
            return R.success(CodeEnum.SUCCESS);
        }
     
    }

    源码获取:博客首页 "资源" 里下载!
————————————————
版权声明:本文为CSDN博主「pastclouds」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yuyecsdn/article/details/122376814



Copyright 2015-2035 西安越影信息技术有限公司 YUEYINGIT.COM | 陕ICP备2020016252号-1
客服QQ:58155571
Top