图书管理系统

Posted 拿红罗卜钓鱼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图书管理系统相关的知识,希望对你有一定的参考价值。

controller层

package cn.hp.controller;

import cn.hp.model.BorrowInfo;
import cn.hp.service.CkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class CkController 

    @Autowired
    private CkService ckService;

    @RequestMapping("/showAll")
    public String showAll(HttpServletRequest request)
        List list = ckService.showAll();
        request.setAttribute("list" , list);
        return "showAll";
    

    @RequestMapping("/showAllBorrow")
    public String showAllBorrow(HttpServletRequest request)
        List list = ckService.showAllBorrow();
        request.setAttribute("list",list);
        return "showAllBorrow";
    

    @RequestMapping("/returnBook")
    public String returnBook(String borrowId)
        ckService.returnBook(borrowId);
        return "forward:showAllBorrow";
    

    @RequestMapping("/add")
    public String add(BorrowInfo borrowInfo)
        boolean addFlag = ckService.add(borrowInfo);
        if (addFlag)
            return "forward:showAllBorrow";
        
        return "forward:add.jsp";
    

dao层

package cn.hp.dao;

import cn.hp.model.BorrowInfo;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CkMapper 
    List selectAll();

    List selectAllBorrow();

    void updateById(String borrowId);

    int add(BorrowInfo borrowInfo);

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="cn.hp.dao.CkMapper">

    <resultMap id="map1" type="cn.hp.model.BorrowInfo">
        <id column="borrowId" property="borrowId"></id>
        <result column="stuName" property="stuName"></result>
        <result column="tel" property="tel"></result>
        <result column="clazz" property="clazz"></result>
        <result column="borrowDate" property="borrowDate"></result>
        <result column="returnDate" property="returnDate"></result>
        <result column="state" property="status"></result>
        <result column="bookId" property="bookId"></result>
        <association property="bookInfo" javaType="cn.hp.model.BookInfo">
            <id column="bookId" property="bookId"></id>
            <result column="bookName" property="bookName"></result>
            <result column="bookWrite" property="bookWrite"></result>
            <result column="bookContent" property="bookContent"></result>
        </association>
    </resultMap>

    <select id="selectAll" resultType="cn.hp.model.BookInfo">
        select * from bookinfo
    </select>

    <select id="selectAllBorrow" resultMap="map1">
        select * from borrowinfo left join bookinfo on borrowinfo.bookid = bookinfo.bookid
    </select>

    <update id="updateById">
        update borrowinfo set returnDate = now() ,  state = 0 where borrowId = #borrowId 
    </update>

    <insert id="add" parameterType="cn.hp.model.BorrowInfo">
        insert into borrowinfo values (null , #stuName ,#clazz , #tel  , now(),null , 1,#bookId  );
    </insert>
</mapper>

model层

package cn.hp.model;

public class BookInfo 
    private int bookId ;
    private String bookName ;
    private String bookWrite ;
    private String bookContent ;

    @Override
    public String toString() 
        return "BookInfo" +
                "bookId=" + bookId +
                ", bookName='" + bookName + '\\'' +
                ", bookWrite='" + bookWrite + '\\'' +
                ", bookContent='" + bookContent + '\\'' +
                '';
    

    public int getBookId() 
        return bookId;
    

    public void setBookId(int bookId) 
        this.bookId = bookId;
    

    public String getBookName() 
        return bookName;
    

    public void setBookName(String bookName) 
        this.bookName = bookName;
    

    public String getBookWrite() 
        return bookWrite;
    

    public void setBookWrite(String bookWrite) 
        this.bookWrite = bookWrite;
    

    public String getBookContent() 
        return bookContent;
    

    public void setBookContent(String bookContent) 
        this.bookContent = bookContent;
    

package cn.hp.model;

public class BorrowInfo 
    private int borrowId ;
    private String stuName ;
    private String clazz ;
    private String tel ;
    private String borrowDate ;
    private String returnDate ;
    private int status ;
    private int bookId ;

    private BookInfo bookInfo ;

    @Override
    public String toString() 
        return "BorrowInfo" +
                "borrowId=" + borrowId +
                ", stuName='" + stuName + '\\'' +
                ", clazz='" + clazz + '\\'' +
                ", tel='" + tel + '\\'' +
                ", borrowDate='" + borrowDate + '\\'' +
                ", returnDate='" + returnDate + '\\'' +
                ", status=" + status +
                ", bookId=" + bookId +
                ", bookInfo=" + bookInfo +
                '';
    

    public int getBorrowId() 
        return borrowId;
    

    public void setBorrowId(int borrowId) 
        this.borrowId = borrowId;
    

    public String getStuName() 
        return stuName;
    

    public void setStuName(String stuName) 
        this.stuName = stuName;
    

    public String getClazz() 
        return clazz;
    

    public void setClazz(String clazz) 
        this.clazz = clazz;
    

    public String getTel() 
        return tel;
    

    public void setTel(String tel) 
        this.tel = tel;
    

    public String getBorrowDate() 
        return borrowDate;
    

    public void setBorrowDate(String borrowDate) 
        this.borrowDate = borrowDate;
    

    public String getReturnDate() 
        return returnDate;
    

    public void setReturnDate(String returnDate) 
        this.returnDate = returnDate;
    

    public int getStatus() 
        return status;
    

    public void setStatus(int status) 
        this.status = status;
    

    public int getBookId() 
        return bookId;
    

    public void setBookId(int bookId) 
        this.bookId = bookId;
    

    public BookInfo getBookInfo() 
        return bookInfo;
    

    public void setBookInfo(BookInfo bookInfo) 
        this.bookInfo = bookInfo;
    

service层

package cn.hp.service;

import cn.hp.dao.CkMapper;
import cn.hp.model.BorrowInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CkService 

    @Autowired
    private CkMapper ckMapper ;

    public List showAll() 
        return ckMapper.selectAll();
    

    public List showAllBorrow() 
        return ckMapper.selectAllBorrow();
    

    public void returnBook(String borrowId) 
        ckMapper.updateById(borrowId);
    

    public boolean add(BorrowInfo borrowInfo) 
        int i = ckMapper.add(borrowInfo);
        if (i > 0 )
            return true;
        
        return false;
    

有问题请指出,一起共同交流进步,谢谢~

以上是关于图书管理系统的主要内容,如果未能解决你的问题,请参考以下文章

1004基于SpringBoot+Vue的图书管理系统

图书管理模块功能设计

用java编写一个 图书馆图书借阅管理系统

《图书管理系统》第1节:图书管理系统简介

java--模拟图书管理系统

用java编写一个,图书管理系统