package com.library.controller;
import com.library.bean.ReaderCard;
import com.library.bean.ReaderInfo;
import com.library.service.LoginService;
import com.library.service.ReaderCardService;
import com.library.service.ReaderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@Controller
public class ReaderController {
@Autowired
private ReaderInfoService readerInfoService;
@Autowired
private LoginService loginService;
@Autowired
private ReaderCardService readerCardService;
private ReaderInfo getReaderInfo(long readerId, String name, String sex, String birth, String address, String phone) {
ReaderInfo readerInfo = new ReaderInfo();
Date date = new Date();
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
date = df.parse(birth);
} catch (ParseException e) {
e.printStackTrace();
}
readerInfo.setAddress(address);
readerInfo.setName(name);
readerInfo.setReaderId(readerId);
readerInfo.setPhone(phone);
readerInfo.setSex(sex);
readerInfo.setBirth(date);
return readerInfo;
}
@RequestMapping("allreaders.html")
public ModelAndView allBooks() {
ArrayList<ReaderInfo> readers = readerInfoService.readerInfos();
ModelAndView modelAndView = new ModelAndView("admin_readers");
modelAndView.addObject("readers", readers);
return modelAndView;
}
@RequestMapping("reader_delete.html")
public String readerDelete(HttpServletRequest request, RedirectAttributes redirectAttributes) {
long readerId = Long.parseLong(request.getParameter("readerId"));
if (readerInfoService.deleteReaderInfo(readerId) && readerCardService.deleteReaderCard(readerId)) {
redirectAttributes.addFlashAttribute("succ", "删除成功!");
} else {
redirectAttributes.addFlashAttribute("error", "删除失败!");
}
return "redirect:/allreaders.html";
}
@RequestMapping("/reader_info.html")
public ModelAndView toReaderInfo(HttpServletRequest request) {
ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard");
ReaderInfo readerInfo = readerInfoService.getReaderInfo(readerCard.getReaderId());
ModelAndView modelAndView = new ModelAndView("reader_info");
modelAndView.addObject("readerinfo", readerInfo);
return modelAndView;
}
@RequestMapping("reader_edit.html")
public ModelAndView readerInfoEdit(HttpServletRequest request) {
long readerId = Long.parseLong(request.getParameter("readerId"));
ReaderInfo readerInfo = readerInfoService.getReaderInfo(readerId);
ModelAndView modelAndView = new ModelAndView("admin_reader_edit");
modelAndView.addObject("readerInfo", readerInfo);
return modelAndView;
}
@RequestMapping("reader_edit_do.html")
public String readerInfoEditDo(HttpServletRequest request, String name, String sex, String birth, String address, String phone, RedirectAttributes redirectAttributes) {
long readerId = Long.parseLong(request.getParameter("readerId"));
ReaderInfo readerInfo = getReaderInfo(readerId, name, sex, birth, address, phone);
if (readerInfoService.editReaderInfo(readerInfo) && readerInfoService.editReaderCard(readerInfo)) {
redirectAttributes.addFlashAttribute("succ", "读者信息修改成功!");
} else {
redirectAttributes.addFlashAttribute("error", "读者信息修改失败!");
}
return "redirect:/allreaders.html";
}
@RequestMapping("reader_add.html")
public ModelAndView readerInfoAdd() {
return new ModelAndView("admin_reader_add");
}
@RequestMapping("reader_add_do.html")
public String readerInfoAddDo(String name, String sex, String birth, String address, String phone, String password, RedirectAttributes redirectAttributes) {
ReaderInfo readerInfo = getReaderInfo(0, name, sex, birth, address, phone);
long readerId = readerInfoService.addReaderInfo(readerInfo);
readerInfo.setReaderId(readerId);
if (readerId > 0 && readerCardService.addReaderCard(readerInfo, password)) {
redirectAttributes.addFlashAttribute("succ", "添加读者信息成功!");
} else {
redirectAttributes.addFlashAttribute("succ", "添加读者信息失败!");
}
return "redirect:/allreaders.html";
}
@RequestMapping("reader_info_edit.html")
public ModelAndView readerInfoEditReader(HttpServletRequest request) {
ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard");
ReaderInfo readerInfo = readerInfoService.getReaderInfo(readerCard.getReaderId());
ModelAndView modelAndView = new ModelAndView("reader_info_edit");
modelAndView.addObject("readerinfo", readerInfo);
return modelAndView;
}
@RequestMapping("reader_edit_do_r.html")
public String readerInfoEditDoReader(HttpServletRequest request, String name, String sex, String birth, String address, String phone, RedirectAttributes redirectAttributes) {
ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard");
ReaderInfo readerInfo = getReaderInfo(readerCard.getReaderId(), name, sex, birth, address, phone);
if (readerInfoService.editReaderInfo(readerInfo) && readerInfoService.editReaderCard(readerInfo)) {
ReaderCard readerCardNew = loginService.findReaderCardByReaderId(readerCard.getReaderId());
request.getSession().setAttribute("readercard", readerCardNew);
redirectAttributes.addFlashAttribute("succ", "信息修改成功!");
} else {
redirectAttributes.addFlashAttribute("error", "信息修改失败!");
}
return "redirect:/reader_info.html";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
概述 基于Spring + Spring MVC + MyBatis的图书馆管理系统,使用Maven进行包管理。主要功能包括:图书查询、图书管理、图书编辑、读者管理、图书的借阅与归还以及借还日志记录等。 环境配置 开发环境:Windows 10,IntelliJ IDEA 2018.3 运行配置 首先安装Mysql5.7,设置用户名为root,密码为123456,并保证其在运行状态,并执行library.sql文件导入数据。 然后再配置Maven到环境变量中,在源代码目录下运行 # mvn jetty:run 使用浏览器访问http://localhost:8080即可进入系统。
资源推荐
资源详情
资源评论
收起资源包目录
基于SSM的图书馆管理系统.zip (85个子文件)
基于SSM的图书馆管理系统
preview
10.png 449KB
9.png 802KB
3.png 78KB
12.png 765KB
1.png 10KB
11.png 966KB
6.png 448KB
5.png 581KB
4.png 14KB
8.png 872KB
7.png 3.35MB
2.png 14KB
pom.xml 5KB
src
main
resources
db.properties 170B
MyBatis
readerInfo.xml 2KB
lend.xml 1KB
admin.xml 801B
readerCard.xml 1KB
book.xml 2KB
book-context.xml 2KB
java
com
library
controller
BookController.java 6KB
WebConfig.java 1KB
LoginController.java 5KB
ReaderController.java 6KB
LendController.java 3KB
dao
ReaderInfoDao.java 2KB
BookDao.java 1KB
LendDao.java 2KB
AdminDao.java 1KB
ReaderCardDao.java 2KB
service
LoginService.java 1KB
BookService.java 986B
LendService.java 902B
ReaderInfoService.java 1KB
ReaderCardService.java 723B
bean
Book.java 2KB
Lend.java 1011B
ReaderInfo.java 1KB
Admin.java 593B
ReaderCard.java 650B
webapp
WEB-INF
web.xml 1KB
book-servlet.xml 1KB
jsp
reader_header.jsp 1KB
admin_header.jsp 3KB
reader_books.jsp 5KB
reader_book_detail.jsp 3KB
reader_lend_list.jsp 3KB
index.jsp 5KB
admin_readers.jsp 3KB
reader_main.jsp 593B
reader_repasswd.jsp 3KB
reader_info_edit.jsp 3KB
admin_repasswd.jsp 3KB
admin_book_add.jsp 4KB
admin_book_edit.jsp 4KB
admin_reader_edit.jsp 3KB
admin_reader_add.jsp 3KB
admin_lend_list.jsp 3KB
reader_info.jsp 2KB
admin_book_detail.jsp 2KB
404.jsp 2KB
admin_main.jsp 2KB
admin_books.jsp 4KB
static
js
bootstrap.min.js 36KB
jquery-3.2.1.js 262KB
js.cookie.js 4KB
img
book2(1).jpg 1.48MB
book3.jpg 16KB
scut.jpg 28KB
u2.jpg 70KB
library1.jpg 39KB
book1.jpg 26KB
lizhi.jpg 93KB
book2.jpg 211KB
timg.jpg 42KB
sky.jpg 105KB
u5.jpeg 241KB
u1.jpg 27KB
wolf.jpg 109KB
school.jpg 26KB
library2.jpg 39KB
classroom.jpg 22KB
library.jpg 26KB
css
bootstrap.min.css 118KB
library.sql 12KB
共 85 条
- 1
资源评论
应用市场
- 粉丝: 928
- 资源: 4169
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功