基于javaweb+mysql的springboot图书管理系统(java+html+springboot+thymeleaf+mysql+maven)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot图书管理系统(java+html+springboot+thymeleaf+mysql+maven)
一、项目运行 环境配置:
Jdk1.8 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
HTML +Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等。
redirectAttributes.addFlashAttribute("error", "旧密码错误!");
return "redirect:/reader_repasswd.html";
//配置404页面
@RequestMapping("*")
public String notFind() {
return "404";
图书管理控制层:
@Controller
public class BookController {
@Autowired
private BookService bookService;
@Autowired
@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(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";
ModelAndView modelAndView = new ModelAndView("admin_book_detail");
modelAndView.addObject("detail", book);
return modelAndView;
@RequestMapping("/reader_book_detail.html")
public ModelAndView readerBookDetail(HttpServletRequest request) {
long bookId = Long.parseLong(request.getParameter("bookId"));
Book book = bookService.getBook(bookId);
ModelAndView modelAndView = new ModelAndView("reader_book_detail");
modelAndView.addObject("detail", book);
return modelAndView;
@RequestMapping("/admin_header.html")
admin.setUsername(username);
request.getSession().setAttribute("admin", admin);
res.put("stateCode", "1");
res.put("msg", "管理员登陆成功!");
} else if (isReader) {
ReaderCard readerCard = loginService.findReaderCardByReaderId(id);
request.getSession().setAttribute("readercard", readerCard);
res.put("stateCode", "2");
res.put("msg", "读者登陆成功!");
} else {
res.put("stateCode", "0");
res.put("msg", "账号或密码错误!");
return res;
String password = loginService.getAdminPassword(id);
if (password.equals(oldPasswd)) {
if (loginService.adminRePassword(id, newPasswd)) {
redirectAttributes.addFlashAttribute("succ", "密码修改成功!");
return "redirect:/admin_repasswd.html";
} else {
redirectAttributes.addFlashAttribute("error", "密码修改失败!");
return "redirect:/admin_repasswd.html";
} else {
redirectAttributes.addFlashAttribute("error", "旧密码错误!");
String passwd = request.getParameter("passwd");
boolean isReader = loginService.hasMatchReader(id, passwd);
boolean isAdmin = loginService.hasMatchAdmin(id, passwd);
HashMap<String, String> res = new HashMap<>();
if (isAdmin) {
Admin admin = new Admin();
admin.setAdminId(id);
admin.setPassword(passwd);
String username = loginService.getAdminUsername(id);
admin.setUsername(username);
request.getSession().setAttribute("admin", admin);
res.put("stateCode", "1");
res.put("msg", "管理员登陆成功!");
@RequestMapping("/reader_book_detail.html")
public ModelAndView readerBookDetail(HttpServletRequest request) {
long bookId = Long.parseLong(request.getParameter("bookId"));
Book book = bookService.getBook(bookId);
ModelAndView modelAndView = new ModelAndView("reader_book_detail");
modelAndView.addObject("detail", book);
return modelAndView;
@RequestMapping("/admin_header.html")
public ModelAndView admin_header() {
return new ModelAndView("admin_header");
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);
@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)) {
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) {
} 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) {
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", "删除成功!");
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) {
return new ModelAndView("reader_header");
@RequestMapping("/reader_books.html")
public ModelAndView readerBooks(HttpServletRequest request) {
ArrayList<Book> books = bookService.getAllBooks();
ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard");
ArrayList<Lend> myAllLendList = lendService.myLendList(readerCard.getReaderId());
ArrayList<Long> myLendList = new ArrayList<>();
for (Lend lend : myAllLendList) {
// 是否已归还
if (lend.getBackDate() == null) {
myLendList.add(lend.getBookId());
ModelAndView modelAndView = new ModelAndView("reader_books");
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", "添加读者信息失败!");
@RequestMapping("/reader_repasswd_do")
public String reReaderPasswdDo(HttpServletRequest request, String oldPasswd, String newPasswd, String reNewPasswd, RedirectAttributes redirectAttributes) {
ReaderCard reader = (ReaderCard) request.getSession().getAttribute("readercard");
long id = reader.getReaderId();
String password = loginService.getReaderPassword(id);
if (password.equals(oldPasswd)) {
if (loginService.readerRePassword(id, newPasswd)) {
redirectAttributes.addFlashAttribute("succ", "密码修改成功!");
return "redirect:/reader_repasswd.html";
} else {
@Autowired
private LendService lendService;
private Date getDate(String pubstr) {
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.parse(pubstr);
} catch (ParseException e) {
e.printStackTrace();
return new Date();
@RequestMapping("/queryBook.html")
public ModelAndView queryBookDo(String searchWord) {
if (bookService.matchBook(searchWord)) {
ArrayList<Book> books = bookService.queryBook(searchWord);