IDEA+Java+SSM+JSP+Mysql实现Web图书管理系统
Posted 水坚石青
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA+Java+SSM+JSP+Mysql实现Web图书管理系统相关的知识,希望对你有一定的参考价值。
目录
一、系统介绍
1.开发环境
开发工具:IDEA2018
JDK版本:jdk1.8
mysql版本:8.0.13
2.技术选型
Java+Spring+SpringMVC+Mybatis+Jsp+Mysql
3.系统功能
1.用户登录退出系统
2.用户借阅查看书籍
3.管理员登录退出系统
4.管理员对书籍的增删改查
5.管理员对书籍类型的增删改查
6.管理员对用户的增删改查
7.管理员对用户类型的增删改查
8.管理员查看借阅记录
4.数据库文件
/*
Navicat Premium Data Transfer
Source Server : MYSQL
Source Server Type : MySQL
Source Server Version : 80013
Source Host : localhost:3306
Source Schema : ssm_library_management
Target Server Type : MySQL
Target Server Version : 80013
File Encoding : 65001
Date: 12/12/2021 16:30:13
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for admin
-- ----------------------------
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin` (
`id` bigint(4) NOT NULL AUTO_INCREMENT,
`username` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`password` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of admin
-- ----------------------------
INSERT INTO `admin` VALUES (1, 'admin', 'admin');
-- ----------------------------
-- Table structure for book
-- ----------------------------
DROP TABLE IF EXISTS `book`;
CREATE TABLE `book` (
`id` bigint(4) NOT NULL AUTO_INCREMENT,
`type` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`number` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`author` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`press` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`publicationdate` date NULL DEFAULT NULL,
`price` decimal(10, 2) NULL DEFAULT NULL,
`pagecount` int(4) NULL DEFAULT NULL,
`keyword` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`createtime` date NULL DEFAULT NULL,
`isborrow` int(4) NULL DEFAULT NULL,
`remark` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `BOOK_PK`(`type`) USING BTREE,
CONSTRAINT `BOOK_PK` FOREIGN KEY (`type`) REFERENCES `booktype` (`number`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE = InnoDB AUTO_INCREMENT = 27 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of book
-- ----------------------------
INSERT INTO `book` VALUES (14, 'bt004', '大雪中的山庄', 'b001', '东野圭吾 ', '北京十月文艺出版社', '2018-06-16', 36.00, 200, NULL, NULL, 0, '1');
INSERT INTO `book` VALUES (16, 'bt004', '特工皇妃', 'b004', '潇湘冬儿', '江苏文艺出版社', '2011-05-05', 74.80, 333, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (17, 'bt006', '人类简史', 'b005', '[以色列] 尤瓦尔·赫拉利 ', '中信出版社', '2014-11-01', 68.00, 100, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (18, 'bt006', '明朝那些事儿(1-9)', 'b006', '当年明月 ', '中国海关出版社', '2009-04-06', 358.20, 500, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (19, 'bt002', '经济学原理(上下)', 'b007', '[美] 曼昆 ', '机械工业出版社', '2003-08-05', 88.00, 156, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (20, 'bt004', '方向', 'b008', '马克-安托万·马修 ', '北京联合出版公司', '2017-04-01', 99.80, 186, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (21, 'bt004', '画的秘密', 'b009', '马克-安托万·马修 ', '北京联合出版公司', '2016-01-01', 60.00, 556, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (22, 'bt004', '造彩虹的人', 'b010', '东野圭吾 ', '北京十月文艺出版社', '2017-06-01', 39.50, 775, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (23, 'bt004', '控方证人', 'b011', '阿加莎·克里斯蒂 ', '新星出版社', '2017-05-01', 35.00, 195, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (24, 'bt004', '少有人走的路', 'b012', 'M·斯科特·派克 ', '吉林文史出版社', '2007-01-01', 26.00, 300, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (25, 'bt004', '追寻生命的意义', 'b013', '[奥] 维克多·弗兰克 ', '新华出版社', '2003-01-01', 12.00, 250, NULL, NULL, 0, NULL);
INSERT INTO `book` VALUES (26, 'bt004', '秘密花园', 'b014', '乔汉娜·贝斯福 ', '北京联合出版公司', '2015-06-01', 42.00, 450, NULL, NULL, 0, NULL);
-- ----------------------------
-- Table structure for booktype
-- ----------------------------
DROP TABLE IF EXISTS `booktype`;
CREATE TABLE `booktype` (
`id` bigint(4) NOT NULL AUTO_INCREMENT,
`number` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`name` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`keyword` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`remark` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`createtime` date NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `number`(`number`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 23 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of booktype
-- ----------------------------
INSERT INTO `booktype` VALUES (5, 'bt001', '军事', NULL, NULL, NULL);
INSERT INTO `booktype` VALUES (6, 'bt002', '经济', NULL, NULL, NULL);
INSERT INTO `booktype` VALUES (8, 'bt003', '语言', NULL, NULL, NULL);
INSERT INTO `booktype` VALUES (9, 'bt004', '文学', NULL, NULL, NULL);
INSERT INTO `booktype` VALUES (10, 'bt005', '艺术', NULL, NULL, NULL);
INSERT INTO `booktype` VALUES (11, 'bt006', '历史', NULL, NULL, NULL);
INSERT INTO `booktype` VALUES (22, 'bt007', '综合', NULL, NULL, NULL);
INSERT INTO `booktype` VALUES (23, 'bt008', '地理', NULL, NULL, NULL);
-- ----------------------------
-- Table structure for reader
-- ----------------------------
DROP TABLE IF EXISTS `reader`;
CREATE TABLE `reader` (
`id` bigint(4) NOT NULL AUTO_INCREMENT,
`number` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`name` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`type` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sex` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`workunit` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`homeaddress` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`tel` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`email` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`createtime` date NULL DEFAULT NULL,
`remark` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of reader
-- ----------------------------
INSERT INTO `reader` VALUES (1, 'r001', '张三', 'rt002', '女', '广州', '广州', '15626277129', '913772015@qq.com', NULL, NULL);
INSERT INTO `reader` VALUES (2, 'r002', '李四', 'rt001', '男', NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `reader` VALUES (5, 'r003', '王五', 'rt001', '男', '市委', '湖南长沙', '12345678911', 'wangwu@qq.com', '2021-12-11', NULL);
-- ----------------------------
-- Table structure for reader_account
-- ----------------------------
DROP TABLE IF EXISTS `reader_account`;
CREATE TABLE `reader_account` (
`id` bigint(4) NOT NULL,
`username` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`password` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of reader_account
-- ----------------------------
INSERT INTO `reader_account` VALUES (1, 'r001', 'r001');
INSERT INTO `reader_account` VALUES (2, 'r002', 'r002');
INSERT INTO `reader_account` VALUES (3, 'r003', 'r003');
-- ----------------------------
-- Table structure for readertype
-- ----------------------------
DROP TABLE IF EXISTS `readertype`;
CREATE TABLE `readertype` (
`id` bigint(4) NOT NULL AUTO_INCREMENT,
`number` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`name` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`borrownumber` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '借书数量',
`borrowterm` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '借书期限',
`remark` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`createtime` date NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of readertype
-- ----------------------------
INSERT INTO `readertype` VALUES (1, 'rt001', '一级读者', '8', '30', NULL, NULL);
INSERT INTO `readertype` VALUES (2, 'rt002', '二级读者', '10', '60', NULL, NULL);
-- ----------------------------
-- Table structure for record
-- ----------------------------
DROP TABLE IF EXISTS `record`;
CREATE TABLE `record` (
`id` bigint(4) NOT NULL AUTO_INCREMENT,
`readernumber` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`booknumber` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`borrowdate` date NULL DEFAULT NULL,
`returndate` date NULL DEFAULT NULL,
`remark` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `reader`(`readernumber`) USING BTREE,
INDEX `book`(`booknumber`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of record
-- ----------------------------
INSERT INTO `record` VALUES (8, 'r002', 'b001', '2018-06-27', '2018-06-27', NULL);
INSERT INTO `record` VALUES (9, 'r001', 'b001', '2018-06-27', '2018-06-27', NULL);
INSERT INTO `record` VALUES (10, 'r001', 'b001', '2018-06-27', '2018-06-27', NULL);
INSERT INTO `record` VALUES (11, 'r001', 'b001', '2021-12-11', '2021-12-11', '');
INSERT INTO `record` VALUES (12, 'r001', 'b001', '2021-12-11', '2021-12-11', NULL);
INSERT INTO `record` VALUES (14, 'r001', 'b001', '2021-12-11', '2021-12-11', 'r001');
INSERT INTO `record` VALUES (15, 'r001', 'b004', '2021-12-11', '2021-12-11', 'r001');
INSERT INTO `record` VALUES (16, 'r001', 'b005', '2021-12-11', '2021-12-11', 'r001');
SET FOREIGN_KEY_CHECKS = 1;
二、系统展示
1.登录系统
2.用户-借阅书籍
3.管理员-图书管理
4.管理员-图书类型管理
5.管理员-读者管理
6.管理员-读者类型管理
7.管理员-借阅记录查看
三、部分代码
BookController
package com.sjsq.controller;
import com.sjsq.pojo.Book;
import com.sjsq.pojo.BookType;
import com.sjsq.pojo.Record;
import com.sjsq.service.BookService;
import com.sjsq.service.ReaderService;
import com.sjsq.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Controller
public class BookController
@Autowired
private BookService bookService;
@Autowired
private RecordService recordService;
@Autowired
private ReaderService readerService;
@RequestMapping("/book/list")
public String bookList(Model model, HttpServletRequest request) throws Exception
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("bookName");
String type = request.getParameter("bookType");
String press = request.getParameter("bookPress");
List<Book> bookList = bookService.queryBook(name, type, press);
List<BookType> bookTypeList = bookService.queryAllBookType();
List<String> bookNumberList = bookService.queryBookNumber();
List<String> readerNumberList = readerService.queryReaderNumber();
model.addAttribute("books", bookList);
request.getSession().setAttribute("bookTypes", bookTypeList);
request.getSession().setAttribute("bookNumbers", bookNumberList);
request.getSession().setAttribute("readerNumbers", readerNumberList);
model.addAttribute("bookName", name);
model.addAttribute("bookType", type);
return "admin_books";
@RequestMapping("/book/listreader")
public String bookListReader(Model model, HttpServletRequest request) throws Exception
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("bookName");
String type = request.getParameter("bookType");
String press = request.getParameter("bookPress");
List<Book> bookList = bookService.queryBook(name, type, press);
List<BookType> bookTypeList = bookService.queryAllBookType();
List<String> bookNumberList = bookService.queryBookNumber();
List<String> readerNumberList = readerService.queryReaderNumber();
model.addAttribute("books", bookList);
request.getSession().setAttribute("bookTypes", bookTypeList);
request.getSession().setAttribute("bookNumbers", bookNumberList);
request.getSession().setAttribute("readerNumbers", readerNumberList);
model.addAttribute("bookName", name);
model.addAttribute("bookType", type);
return "reader_books";
@RequestMapping("/book/edit.action")
public @ResponseBody
Book bookEdit(String number)
Book book = bookService.queryBookByNumber(number);
return book;
@RequestMapping("/book/update.action")
public @ResponseBody
String bookUpdate(Book book)
bookService.updateBookById(book);
return "OK";
/*用book实体接收不了前端传过来的变量,只能一个一个收*/
@RequestMapping("/book/add.action")
public @ResponseBody
String bookAdd(HttpServletRequest request) throws Exception
Date publicationdate = null;
Integer pagecount = null;
BigDecimal price = null;
String name = request.getParameter("name");
String type = request.getParameter("type");
String author = request.getParameter("anthor");
String number = request.getParameter("number");
String press = request.getParameter("press");
String publicationdateStr = request.getParameter("publicationdate");
String priceStr = request.getParameter("price");
String pagecountStr = request.getParameter("pagecount");
String remark = request.getParameter("remark");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String createtimeStr = sdf.format(new Date());
Date createtime = sdf.parse(createtimeStr);
if (publicationdateStr != "")
publicationdate = sdf.parse(publicationdateStr);
if (pagecountStr != "")
pagecount = Integer.parseInt(pagecountStr);
if (priceStr != "")
price = new BigDecimal(priceStr);
Book book = new Book(type, name, number, author, press, publicationdate,
price, pagecount, createtime, 0, remark);
bookService.addBook(book);
return "OK";
@RequestMapping("/book/delete.action")
public @ResponseBody
String bookDelete(String number)
bookService.deleteBookByNumber(number);
return "OK";
@RequestMapping("/book/lent.action")
public @ResponseBody
String lentBook(HttpServletRequest request) throws Exception
String bookNumber = request.getParameter("bookNumber");
String readerNumber = request.getParameter("readerNumber");
String remark = request.getParameter("remark");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String borrowtimeStr = sdf.format(new Date());
Date borrowtime = sdf.parse(borrowtimeStr);
Record record = new Record();
record.setReaderNumber(readerNumber);
record.setBookNumber(bookNumber);
record.setBorrowDate(borrowtime);
record.setRemark(remark);
bookService.updateBookStatusByNumber(1, bookNumber);
recordService.addRecord(record);
return "OK";
@RequestMapping("/book/return.action")
public @ResponseBody
String returnBook(HttpServletRequest request) throws Exception
String bookNumber = request.getParameter("bookNumber");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String returntimeStr = sdf.format(new Date());
Date returntime = sdf.parse(returntimeStr);
bookService.updateBookStatusByNumber(0, bookNumber);
recordService.setReturnDate(bookNumber, returntime);
return "OK";
@RequestMapping("/record/list")
public String recordList(Model model, HttpServletRequest request) throws Exception
request.setCharacterEncoding("UTF-8");
List<Record> recordList = recordService.queryAllFullRecord();
model.addAttribute("records", recordList);
return "record";
BookTypeController
package com.sjsq.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sjsq.pojo.BookType;
import com.sjsq.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Controller
public class BookTypeController
@Autowired
private BookService bookService;
@RequestMapping("/booktype/list")
public String bookTypeList(Model model, HttpServletRequest request) throws Exception
request.setCharacterEncoding("UTF-8");
List<BookType> bookTypeList = bookService.queryAllBookType();
ObjectMapper om = new ObjectMapper();
String jsonStr = om.writeValueAsString(bookTypeList);
System.out.println(jsonStr);
model.addAttribute("bookTypes", bookTypeList); //前端foreach标签好像解析不了json
model.addAttribute("bookTypesJSON", jsonStr);
return "admin_booktype";
@RequestMapping("/booktype/edit.action")
public @ResponseBody
BookType bookTypeEdit(String number)
BookType booktype = bookService.queryBookTypeByNumber(number);
return booktype;
@RequestMapping("/booktype/update.action")
public @ResponseBody
String bookTypeUpdate(BookType bookType)
bookService.updateBookTypeById(bookType);
return "OK";
@RequestMapping("/booktype/add.action")
public @ResponseBody
String bookTypeAdd(HttpServletRequest request) throws Exception
/*private int id;
private String number;
private String name;
private String keyword;
private String remark;*/
String name = request.getParameter("name");
String number = request.getParameter("number");
String remark = request.getParameter("remark");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String createtimeStr = sdf.format(new Date());
Date createtime = sdf.parse(createtimeStr);
BookType bookType = new BookType(number, name, remark, createtime);
bookService.addBookType(bookType);
return "OK";
@RequestMapping("/booktype/delete.action")
public @ResponseBody
String bookTypeDelete(String number)
bookService.deleteBookTypeByNumber(number);
return "OK";
LoginController
package com.sjsq.controller;
import com.sjsq.pojo.Admin;
import com.sjsq.pojo.ReaderAccount;
import com.sjsq.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
@Controller
public class LoginController
@Autowired
private LoginService loginService;
@RequestMapping(value = "/", "/login.html")
public String toLogin(HttpServletRequest request)
return "index";
@RequestMapping("/logout.html")
public String logout(HttpServletRequest request)
return "redirect:/login.html";
@RequestMapping("/logincheck")
public @ResponseBody
Object loginCheck(HttpServletRequest request)
HashMap<String, String> res = new HashMap<String, String>();
String username = request.getParameter("username");
String password = request.getParameter("password");
Admin admin = loginService.queryAdminByUsernameAndPasswd(username, password);
ReaderAccount readerAccount = loginService.queryReaderAccountByUsernameAndPasswd(username, password);
if (admin != null && readerAccount == null)
res.put("stateCode", "1");
request.getSession().setAttribute("admin", admin);
else if (admin == null && readerAccount != null)
res.put("stateCode", "2");
request.getSession().setAttribute("readerAccount", readerAccount);
else
res.put("stateCode", "0");
return res;
@RequestMapping("/admin_main.html")
public String toAdminMain(HttpServletResponse response)
return "admin_main";
@RequestMapping("/reader_main.html")
public String toReaderMain(HttpServletResponse response)
return "reader_main";
ReaderTypeController
package com.sjsq.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sjsq.pojo.ReaderType;
import com.sjsq.service.ReaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Controller
public class ReaderTypeController
@Autowired
private ReaderService readerService;
@RequestMapping("/readertype/list")
public String readerTypeList(Model model, HttpServletRequest request) throws Exception
request.setCharacterEncoding("UTF-8");
List<ReaderType> readerTypeList = readerService.queryAllReaderType();
ObjectMapper om = new ObjectMapper();
String jsonStr = om.writeValueAsString(readerTypeList);
System.out.println(jsonStr);
model.addAttribute("readerTypes", readerTypeList); //前端foreach标签好像解析不了json
model.addAttribute("readerTypesJSON", jsonStr);
return "admin_readertype";
@RequestMapping("/readertype/edit.action")
public @ResponseBody
ReaderType readerTypeEdit(String number)
ReaderType readertype = readerService.queryReaderTypeByNumber(number);
return readertype;
@RequestMapping("/readertype/update.action")
public @ResponseBody
String readerTypeUpdate(ReaderType readerType)
readerService.updateReaderTypeById(readerType);
return "OK";
@RequestMapping("/readertype/add.action")
public @ResponseBody
String readerTypeAdd(HttpServletRequest request) throws Exception
String name = request.getParameter("name");
String number = request.getParameter("number");
String borrownumber = request.getParameter("borrownumber");
String borrowterm = request.getParameter("borrowterm");
String remark = request.getParameter("remark");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String createtimeStr = sdf.format(new Date());
Date createtime = sdf.parse(createtimeStr);
ReaderType readerType = new ReaderType(number, name, borrownumber, borrowterm, remark, createtime);
readerService.addReaderType(readerType);
return "OK";
@RequestMapping("/readertype/delete.action")
public @ResponseBody
String readerTypeDelete(String number)
readerService.deleteReaderTypeByNumber(number);
return "OK";
四、其他
1.更多系统
Java+JSP系统系列实现
Java+Servlet系统系列实现
Java+SSM系统系列实现
Java+SSH系统系列实现
Java+Springboot系统系列实现
Java+Springboot+H-ui+Maven实现营销管理系统
Java+Springboot+Bootstrap+Maven实现网上商城系统
Java+Springboot+Bootstrap+Maven实现景区旅游管理系统
1.更多JavaWeb系统请关注专栏。
2.更多JavaSwing系统请关注专栏。
2.源码下载
sql在sql文件夹下面
3.备注
如有侵权请联系我删除。
4.支持博主
如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!想要获取其他资源可关注左侧微信公众号获取!
以上是关于IDEA+Java+SSM+JSP+Mysql实现Web图书管理系统的主要内容,如果未能解决你的问题,请参考以下文章
IDEA+Java+SSM+JSP+Mysql实现Web图书管理系统
IDEA+Java+SSM+Mysql+JSP实现Web宠物商城系统
IDEA+Java+SSM+JSP+Mysql+Tomcat实现Web药品信息管理系统
IDEA+Java+SSM+Mysql+Bootstrap+Maven实现网上书城系统