项目介绍
本系统分为管理员与普通用户两种角色;
管理员角色包含以下功能:
借书管理,图书信息管理,图书分类管理,用户管理,角色管理,还书管理,登录页面等功能。
用户角色包含以下功能:
借阅管理,图书检索,查看借还记录,查看图书详情,还书管理,登录页面等功能。
环境需要
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.数据库:MySql 5.7版本;
6.是否Maven项目:是;
技术栈
后端:SpringBoot
前端:JSP+CSS+JavaScript+bootstrap
使用说明
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
ModelAndView modelAndView = new ModelAndView("reader_books");
modelAndView.addObject("books", books);
modelAndView.addObject("myLendList", myLendList);
return modelAndView;
}
}
登录控制层:
@Controller
public class LoginController {
private LoginService loginService;
@Autowired
public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}
@RequestMapping(value = {"/", "/login.html"})
public String toLogin(HttpServletRequest request) {
request.getSession().invalidate();
return "index";
}
@RequestMapping("/logout.html")
public String logout(HttpServletRequest request) {
request.getSession().invalidate();
return "redirect:/login.html";
}
//负责处理loginCheck.html请求
//请求参数会根据参数名称默认契约自动绑定到相应方法的入参中
@RequestMapping(value = "/api/loginCheck", method = RequestMethod.POST)
}
}
@RequestMapping("/admin_books.html")
public ModelAndView adminBooks() {
ArrayList<Book> books = bookService.getAllBooks();
ModelAndView modelAndView = new ModelAndView("admin_books");
modelAndView.addObject("books", books);
return modelAndView;
}
@RequestMapping("/book_add.html")
public ModelAndView addBook() {
return new ModelAndView("admin_book_add");
}
@RequestMapping("/book_add_do.html")
public String addBookDo(@RequestParam(value = "pubstr") String pubstr, Book book, RedirectAttributes redirectAttributes) {
book.setPubdate(getDate(pubstr));
if (bookService.addBook(book)) {
redirectAttributes.addFlashAttribute("succ", "图书添加成功!");
} else {
redirectAttributes.addFlashAttribute("succ", "图书添加失败!");
}
return "redirect:/admin_books.html";
}
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);
modelAndView.addObject("books", books);
return modelAndView;
} else {
return new ModelAndView("admin_books", "error", "没有匹配的图书");
}
}
@RequestMapping("/reader_querybook_do.html")
public ModelAndView readerQueryBookDo(String searchWord) {
if (bookService.matchBook(searchWord)) {
ArrayList<Book> books = bookService.queryBook(searchWord);
ModelAndView modelAndView = new ModelAndView("reader_books");
modelAndView.addObject("books", books);
return modelAndView;
} else {
return new ModelAndView("reader_books", "error", "没有匹配的图书");
}
}
@RequestMapping("/admin_books.html")
public ModelAndView adminBooks() {
ArrayList<Book> books = bookService.getAllBooks();
ModelAndView modelAndView = new ModelAndView("admin_books");
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;
}
@RequestMapping("/admin_main.html")
public ModelAndView toAdminMain(HttpServletResponse response) {
return new ModelAndView("admin_main");
}
@RequestMapping("/reader_main.html")
public ModelAndView toReaderMain(HttpServletResponse response) {
return new ModelAndView("reader_main");
}
@RequestMapping("/admin_repasswd.html")
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";
}
}
图书管理控制层:
@Controller
public class BookController {
@Autowired
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);
} else {
redirectAttributes.addFlashAttribute("error", "旧密码错误!");
return "redirect:/reader_repasswd.html";
}
}
//配置404页面
@RequestMapping("*")
public String notFind() {
return "404";
}
}
读者控制层:
@Controller
public class ReaderController {
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")
@RequestMapping("/admin_books.html")
public ModelAndView adminBooks() {
ArrayList<Book> books = bookService.getAllBooks();
ModelAndView modelAndView = new ModelAndView("admin_books");
modelAndView.addObject("books", books);
return modelAndView;
}
@RequestMapping("/book_add.html")
public ModelAndView addBook() {
return new ModelAndView("admin_book_add");
}
@RequestMapping("/book_add_do.html")
public String addBookDo(@RequestParam(value = "pubstr") String pubstr, Book book, RedirectAttributes redirectAttributes) {
book.setPubdate(getDate(pubstr));
if (bookService.addBook(book)) {
redirectAttributes.addFlashAttribute("succ", "图书添加成功!");
} else {
redirectAttributes.addFlashAttribute("succ", "图书添加失败!");
}
return "redirect:/admin_books.html";
}
@RequestMapping("/updatebook.html")
public ModelAndView bookEdit(HttpServletRequest request) {
long bookId = Long.parseLong(request.getParameter("bookId"));
Book book = bookService.getBook(bookId);
ModelAndView modelAndView = new ModelAndView("admin_book_edit");
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", "读者信息修改失败!");
}