Java课程设计——图书管理系统

文章最下方获取源码!!!
文章最下方获取源码!!!
文章最下方获取源码!!!

一、需求分析

1、实现登录基本逻辑
2、实现登录后对图书的管理,包括增、删、改、查
3、实现登录后对用户的管理,包括增、删、改、查
4、用户可以借阅处于空闲状态的图书,被借阅后的图书不能再被其他用户借阅,用户可以归还图书,归还后的图书可以再次被借阅

二、技术介绍

2.1相关技术

  • Spring + SpringMVC + MyBatis(SSM)
  • Jsp + JQuery
  • Mysql

2.2开发环境

idea + tomcat

三、功能实现

1、登录

在这里插入图片描述

2、图书管理

2.1图书列表

在这里插入图片描述

2.2添加图书

在这里插入图片描述

2.3修改图书信息

在这里插入图片描述

2.4查询图书信息

在这里插入图片描述

3、用户管理

3.1借阅图书

在这里插入图片描述

3.2修改借阅信息

在这里插入图片描述

3.3归还图书

在这里插入图片描述

4、退出系统

在这里插入图片描述

四、部分代码实现

BookMapper.java

package com.codejams.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.codejams.domain.Book;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;


public interface BookMapper{

    List<Book> findAllBook();

    Book findBookById(int id);

    void update(Book book);

    void save(Book book);

    void delete(int id);

    List<Book> findBookByCondition(String condition);

    void changeStatusToLeisure(String name);

    void changeStatusToNotLeisure(String name);

}

BorrowerController.java

package com.codejams.controller;

import com.codejams.domain.Book;
import com.codejams.domain.Borrower;
import com.codejams.service.BookService;
import com.codejams.service.BorrowerService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/borrower")
public class BorrowerController {

    private BorrowerService borrowerService = new BorrowerService();
    private BookService bookService = new BookService();


    @RequestMapping("/findAllBorrower")
    public ModelAndView findAllBorrower(){

        ModelAndView modelAndView = new ModelAndView();

        List<Borrower> borrowerList = borrowerService.findAllBorrower();
        List<Book> bookList = bookService.findAllBook();

        //设置视图
        modelAndView.setViewName("/workbench/activity/borrower-list.jsp");
        modelAndView.addObject("borrowerList",borrowerList);
        modelAndView.addObject("bookList",bookList);

        return modelAndView;
    }

    @RequestMapping("/findBorrowerByCondition")
    public ModelAndView findBookByCondition(String condition){

        ModelAndView modelAndView = new ModelAndView();

        System.out.println(condition);
        List<Borrower> borrowerList = borrowerService.findBorrowerByCondition(condition);
        List<Book> bookList = bookService.findAllBook();
        for (Borrower borrower : borrowerList) {
            System.out.println(borrower);
        }


        //设置视图
        modelAndView.setViewName("/workbench/activity/borrower-list.jsp");
        modelAndView.addObject("borrowerList",borrowerList);
        modelAndView.addObject("bookList",bookList);

        return modelAndView;
    }

    @RequestMapping("/save")
    public String save(Borrower borrower){
        System.out.println(borrower);
        borrowerService.save(borrower);

        //保存后将改书的状态改为已借出
        bookService.changeStatusToNotLeisure(borrower.getBook());

        return "redirect:findAllBorrower";
    }

    @RequestMapping("/delete")
    public String delete(int id){
        Borrower borrower = borrowerService.findBorrowerById(id);
        //将对应的书修改为空闲状态
        bookService.changeStatusToLeisure(borrower.getBook());
        borrowerService.delete(id);

        return "redirect:findAllBorrower";
    }

    @RequestMapping("/update")
    public String update(Borrower borrower){
        System.out.println(borrower);
        //修改前先将书的状态改为空闲
        int id = borrower.getId();
        Borrower bor = borrowerService.findBorrowerById(id);
        bookService.changeStatusToLeisure(bor.getBook());

        borrowerService.update(borrower);
        bookService.changeStatusToNotLeisure(borrower.getBook());


        return "redirect:findAllBorrower";
    }

    @RequestMapping(value = "/findBorrower", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String findBorrower(String id){
        int bid = Integer.parseInt(id);
        System.out.println(bid);

        Borrower borrower = borrowerService.findBorrowerById(bid);
        System.out.println(borrower);

        ObjectMapper objectMapper = new ObjectMapper();

        String json = null;
        try {
            json = objectMapper.writeValueAsString(borrower);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return json;
    }

}

获取源码

  • 我的微信
  • 欢迎添加微信互相交流学习哦!