基于javaweb+mysql的springboot图书管理系统(java+springboot+html+thymeleaf+bootstrap+maven+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot图书管理系统(java+springboot+html+thymeleaf+bootstrap+maven+mysql)
项目介绍
该项目分为管理员与读者两种角色,主要功能有:
-
登录、注销、修改密码 2. 管理员主要功能包括:图书管理、读者管理、借还管理。对图书信息的增删改查、查看读者、查看借阅记录等;
-
读者对图书信息的查看查询、修改个人信息、查看借阅记录
共7张表;
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 8.0版本;
技术栈
数据库:mysql5.7 后端框架: SpringBoot HTML模板: ThymeLeaf 持久层: Mybatis UI: Bootstrap
登录验证和用户权限: SpringSecurity
使用说明
本项目使用maven进行管理,详细安装教程自行百度 1. 需下载mysql图形化管理工具(例如Navicat),新建数据库library,右键数据库–>运行项目中的library.sql脚本 2. 打开项目(idea或eclipse皆可,但需配置好maven环境),打开src/main/resources/application.yml,将数据库的username和password修改成你自己的mysql的用户名和密码 3. 找到BookmanagerApplication类运行main方法,打开浏览器,网址栏输入localhost:8080访问系统
- 如果不想用IDE打开项目而是想直接运行的朋友们,在目录下打开cmd键入mvn package命令,然后在target/目录下会生成对应的jar包,在cmd用“java -jar jar包名”运行即可
注意事项
- 高版本mysql在登录时可能会报空指针错误,出现问题的建议安装并使用mysql5.7版本
session.setAttribute("name", name);
session.setAttribute("username", username);
}
filterChain.doFilter(servletRequest, servletResponse);
}
}
package com.lyx.bookmanager.controller;
@Controller
public class UserController {
@Autowired
private UserMapper userMapper;
@RequestMapping("/toChPwdPage")
public String toChangePasswordPage() {
return "password";
}
@RequestMapping("/changePassword")
public String changePassword(HttpSession session, String newPassword) {
String username = (String) session.getAttribute("username");
userMapper.changePassword(username, newPassword);
return "redirect:/";
}
@RequestMapping("/checkPassword")
@ResponseBody
public String checkPassword(@RequestParam("password") String password, HttpSession session) {
String username = (String) session.getAttribute("username");
String realPassword = userMapper.getPassword(username);
if (realPassword.equals(password))
return "1";
else
return "0";
@Controller
@RequestMapping("/admin/reader")
public class AdminReaderController {
@Autowired
private ReaderMapper readerMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Reader> readers = readerMapper.getAllReader();
model.addAttribute("readers", readers);
return "admin/readers";
}
}
package com.lyx.bookmanager.controller.admin;
@Controller
@RequestMapping("/admin/record")
public class AdminRecordController {
@Autowired
private RecordMapper recordMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Record> records = recordMapper.getAllRecord();
model.addAttribute("records", records);
return "admin/records";
}
}
package com.lyx.bookmanager.controller;
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_info";
}
@RequestMapping("/toEditPage/{id}")
public String toEditPage(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_edit";
}
@RequestMapping("/update")
public String update(Book book) {
bookMapper.updateBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/delete/{id}")
public String delete(@PathVariable("id") long id) {
bookMapper.deleteBook(id);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/toAddPage")
public String toAddPage() {
return "admin/book_add";
}
@RequestMapping("/add")
public String add(Book book) {
bookMapper.addBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "admin/book_search_result";
}
}
package com.lyx.bookmanager.config;
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpSession session = request.getSession();
if (session.getAttribute("name") == null) {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = ((UserDetails) principal).getUsername();
String name = "管理员";
if (!username.equals("admin")) {
name = readerMapper.getReaderName(username);
}
session.setAttribute("name", name);
session.setAttribute("username", username);
}
filterChain.doFilter(servletRequest, servletResponse);
}
}
package com.lyx.bookmanager.controller;
@Controller
public class UserController {
@Autowired
private UserMapper userMapper;
@RequestMapping("/toChPwdPage")
public String toChangePasswordPage() {
return "password";
}
@RequestMapping("/changePassword")
public String changePassword(HttpSession session, String newPassword) {
String username = (String) session.getAttribute("username");
userMapper.changePassword(username, newPassword);
return "redirect:/";
}
@RequestMapping("/add")
public String add(Book book) {
bookMapper.addBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "admin/book_search_result";
}
}
package com.lyx.bookmanager.config;
@WebFilter(urlPatterns = { "/", "/index", "/admin/*", "/user/*", "/toChPwdPage" })
public class SessionFilter implements Filter {
private ReaderMapper readerMapper;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext servletContext = filterConfig.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
readerMapper = (ReaderMapper)ctx.getBean("readerMapper");
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpSession session = request.getSession();
if (session.getAttribute("name") == null) {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = ((UserDetails) principal).getUsername();
model.addAttribute("books", books);
return "user/book_search_result";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/user")
public class UserReaderController {
@Autowired
private ReaderMapper readerMapper;
@RequestMapping("/toInfoPage")
public String toInfoPage(HttpSession session, Model model) {
String username = (String) session.getAttribute("username");
Reader info = readerMapper.getReaderInfo(username);
model.addAttribute("info", info);
return "user/reader_info";
}
@RequestMapping("/info/update")
public String update(Reader reader) {
readerMapper.updateInfo(reader);
return "redirect:/user/toInfoPage";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/add")
public String add(Book book) {
bookMapper.addBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "admin/book_search_result";
}
}
package com.lyx.bookmanager.config;
@WebFilter(urlPatterns = { "/", "/index", "/admin/*", "/user/*", "/toChPwdPage" })
public class SessionFilter implements Filter {
private ReaderMapper readerMapper;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext servletContext = filterConfig.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
readerMapper = (ReaderMapper)ctx.getBean("readerMapper");
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "admin/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_info";
}
@RequestMapping("/toEditPage/{id}")
public String toEditPage(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_edit";
}
@RequestMapping("/update")
public String update(Book book) {
bookMapper.updateBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/delete/{id}")
public String delete(@PathVariable("id") long id) {
bookMapper.deleteBook(id);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/toAddPage")
public String toAddPage() {
return "admin/book_add";
}
@RequestMapping("/add")
public String add(Book book) {
bookMapper.addBook(book);
@Autowired
private BookMapper bookMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "user/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "user/book_info";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "user/book_search_result";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/user")
public class UserReaderController {
@Autowired
private ReaderMapper readerMapper;
@RequestMapping("/toInfoPage")
public String toInfoPage(HttpSession session, Model model) {
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "admin/book_search_result";
}
}
package com.lyx.bookmanager.config;
@WebFilter(urlPatterns = { "/", "/index", "/admin/*", "/user/*", "/toChPwdPage" })
public class SessionFilter implements Filter {
private ReaderMapper readerMapper;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext servletContext = filterConfig.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
readerMapper = (ReaderMapper)ctx.getBean("readerMapper");
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpSession session = request.getSession();
@RequestMapping("/add")
public String add(Book book) {
bookMapper.addBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "admin/book_search_result";
}
}
package com.lyx.bookmanager.config;
@WebFilter(urlPatterns = { "/", "/index", "/admin/*", "/user/*", "/toChPwdPage" })
public class SessionFilter implements Filter {
private ReaderMapper readerMapper;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext servletContext = filterConfig.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
readerMapper = (ReaderMapper)ctx.getBean("readerMapper");
}
@Override
model.addAttribute("info", info);
return "user/reader_info";
}
@RequestMapping("/info/update")
public String update(Reader reader) {
readerMapper.updateInfo(reader);
return "redirect:/user/toInfoPage";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/user/record")
public class UserRecordController {
@Autowired
private RecordMapper recordMapper;
@RequestMapping("/getOwnRecord")
public String ownRecord(Model model, HttpSession session) {
String username = (String) session.getAttribute("username");
List<Record> records = recordMapper.getOwnRecord(username);
model.addAttribute("records", records);
return "user/ownRecord";
}
}
package com.lyx.bookmanager.controller.admin;
@Controller
@RequestMapping("/admin/reader")
public class AdminReaderController {
@Autowired
private ReaderMapper readerMapper;
return "redirect:/admin/book/getAll";
}
@RequestMapping("/toAddPage")
public String toAddPage() {
return "admin/book_add";
}
@RequestMapping("/add")
public String add(Book book) {
bookMapper.addBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "admin/book_search_result";
}
}
package com.lyx.bookmanager.config;
@WebFilter(urlPatterns = { "/", "/index", "/admin/*", "/user/*", "/toChPwdPage" })
public class SessionFilter implements Filter {
private ReaderMapper readerMapper;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext servletContext = filterConfig.getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
readerMapper = (ReaderMapper)ctx.getBean("readerMapper");
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
@Controller
@RequestMapping("/user/book")
public class UserBookController {
@Autowired
private BookMapper bookMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "user/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "user/book_info";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "user/book_search_result";
}
}
package com.lyx.bookmanager.controller.user;
public class UserBookController {
@Autowired
private BookMapper bookMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "user/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "user/book_info";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "user/book_search_result";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/user")
public class UserReaderController {
@Autowired
private ReaderMapper readerMapper;
@RequestMapping("/toInfoPage")
public String toInfoPage(HttpSession session, Model model) {
String username = (String) session.getAttribute("username");
Reader info = readerMapper.getReaderInfo(username);
model.addAttribute("info", info);
return "user/reader_info";
}
@RequestMapping("/info/update")
public String update(Reader reader) {
readerMapper.updateInfo(reader);
@RequestMapping("/delete/{id}")
public String delete(@PathVariable("id") long id) {
bookMapper.deleteBook(id);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/toAddPage")
public String toAddPage() {
return "admin/book_add";
}
@RequestMapping("/add")
public String add(Book book) {
bookMapper.addBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "admin/book_search_result";
}
}
package com.lyx.bookmanager.config;
@WebFilter(urlPatterns = { "/", "/index", "/admin/*", "/user/*", "/toChPwdPage" })
public class SessionFilter implements Filter {
private ReaderMapper readerMapper;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
@Controller
@RequestMapping("/admin/reader")
public class AdminReaderController {
@Autowired
private ReaderMapper readerMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Reader> readers = readerMapper.getAllReader();
model.addAttribute("readers", readers);
return "admin/readers";
}
}
package com.lyx.bookmanager.controller.admin;
@Controller
@RequestMapping("/admin/record")
public class AdminRecordController {
@Autowired
private RecordMapper recordMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Record> records = recordMapper.getAllRecord();
model.addAttribute("records", records);
return "admin/records";
}
}
package com.lyx.bookmanager.controller;
}
}
package com.lyx.bookmanager.controller.admin;
@Controller
@RequestMapping("/admin/reader")
public class AdminReaderController {
@Autowired
private ReaderMapper readerMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Reader> readers = readerMapper.getAllReader();
model.addAttribute("readers", readers);
return "admin/readers";
}
}
package com.lyx.bookmanager.controller.admin;
@Controller
@RequestMapping("/admin/record")
public class AdminRecordController {
@Autowired
private RecordMapper recordMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Record> records = recordMapper.getAllRecord();
model.addAttribute("records", records);
return "admin/records";
}
}
@Controller
@RequestMapping("/user/book")
public class UserBookController {
@Autowired
private BookMapper bookMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "user/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "user/book_info";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "user/book_search_result";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/user")
public class UserReaderController {
}
@RequestMapping("/checkPassword")
@ResponseBody
public String checkPassword(@RequestParam("password") String password, HttpSession session) {
String username = (String) session.getAttribute("username");
String realPassword = userMapper.getPassword(username);
if (realPassword.equals(password))
return "1";
else
return "0";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/user/book")
public class UserBookController {
@Autowired
private BookMapper bookMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "user/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "user/book_info";
}
public class AdminBookController {
@Autowired
private BookMapper bookMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "admin/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_info";
}
@RequestMapping("/toEditPage/{id}")
public String toEditPage(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_edit";
}
@RequestMapping("/update")
public String update(Book book) {
bookMapper.updateBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/delete/{id}")
public String delete(@PathVariable("id") long id) {
bookMapper.deleteBook(id);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/toAddPage")
public String toAddPage() {
return "admin/book_add";
}
@RequestMapping("/add")
public String add(Book book) {
bookMapper.addBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "user/book_search_result";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/user")
public class UserReaderController {
@Autowired
private ReaderMapper readerMapper;
@RequestMapping("/toInfoPage")
public String toInfoPage(HttpSession session, Model model) {
String username = (String) session.getAttribute("username");
Reader info = readerMapper.getReaderInfo(username);
model.addAttribute("info", info);
return "user/reader_info";
}
@RequestMapping("/info/update")
public String update(Reader reader) {
readerMapper.updateInfo(reader);
return "redirect:/user/toInfoPage";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/admin/book")
public class AdminBookController {
@Autowired
private BookMapper bookMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "admin/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_info";
}
@RequestMapping("/toEditPage/{id}")
public String toEditPage(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_edit";
}
@RequestMapping("/update")
public String update(Book book) {
bookMapper.updateBook(book);
return "redirect:/admin/book/getAll";
}
@Controller
@RequestMapping("/user/record")
public class UserRecordController {
@Autowired
private RecordMapper recordMapper;
@RequestMapping("/getOwnRecord")
public String ownRecord(Model model, HttpSession session) {
String username = (String) session.getAttribute("username");
List<Record> records = recordMapper.getOwnRecord(username);
model.addAttribute("records", records);
return "user/ownRecord";
}
}
package com.lyx.bookmanager.controller.admin;
@Controller
@RequestMapping("/admin/reader")
public class AdminReaderController {
@Autowired
private ReaderMapper readerMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Reader> readers = readerMapper.getAllReader();
model.addAttribute("readers", readers);
return "admin/readers";
}
}
package com.lyx.bookmanager.controller.admin;
@Controller
@RequestMapping("/user/book")
public class UserBookController {
@Autowired
private BookMapper bookMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "user/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "user/book_info";
}
@RequestMapping("/search")
public String search(String keyword, Model model) {
List<Book> books = bookMapper.searchBook(keyword);
model.addAttribute("books", books);
return "user/book_search_result";
}
}
package com.lyx.bookmanager.controller.user;
@Controller
@RequestMapping("/admin/book")
public class AdminBookController {
@Autowired
private BookMapper bookMapper;
@RequestMapping("/getAll")
public String getAll(Model model) {
List<Book> books = bookMapper.getAllBook();
model.addAttribute("books", books);
return "admin/books";
}
@RequestMapping("/info/{id}")
public String info(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_info";
}
@RequestMapping("/toEditPage/{id}")
public String toEditPage(Model model, @PathVariable("id") String id) {
Book book = bookMapper.getBookById(id);
model.addAttribute("book", book);
return "admin/book_edit";
}
@RequestMapping("/update")
public String update(Book book) {
bookMapper.updateBook(book);
return "redirect:/admin/book/getAll";
}
@RequestMapping("/delete/{id}")
public String delete(@PathVariable("id") long id) {
bookMapper.deleteBook(id);
return "redirect:/admin/book/getAll";