标签:教程 bookId 管理系统 request html redirectAttributes 新手 addFlashAttribute 图书
图书馆管理系统
概述
基于Spring + Spring MVC + MyBatis的图书馆管理系统,使用Maven进行包管理。主要功能包括:图书查询、图书管理、图书编辑、读者管理、图书的借阅与归还以及借还日志记录等。
代码
@Controller
public class LendController {
@Autowired
private LendService lendService;
@Autowired
private BookService bookService;
@RequestMapping("/deletebook.html")
public String deleteBook(HttpServletRequest request, RedirectAttributes redirectAttributes) {
long bookId = Long.parseLong(request.getParameter("bookId"));
if (bookService.deleteBook(bookId)) {
redirectAttributes.addFlashAttribute("succ", "图书删除成功!");
} else {
redirectAttributes.addFlashAttribute("error", "图书删除失败!");
}
return "redirect:/admin_books.html";
}
@RequestMapping("/lendlist.html")
public ModelAndView lendList(HttpServletRequest request) {
ModelAndView modelAndView = new ModelAndView("admin_lend_list");
modelAndView.addObject("list", lendService.lendList());
return modelAndView;
}
@RequestMapping("/mylend.html")
public ModelAndView myLend(HttpServletRequest request) {
ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard");
ModelAndView modelAndView = new ModelAndView("reader_lend_list");
modelAndView.addObject("list", lendService.myLendList(readerCard.getReaderId()));
return modelAndView;
}
@RequestMapping("/deletelend.html")
public String deleteLend(HttpServletRequest request, RedirectAttributes redirectAttributes) {
long serNum = Long.parseLong(request.getParameter("serNum"));
if (lendService.deleteLend(serNum) > 0) {
redirectAttributes.addFlashAttribute("succ", "记录删除成功!");
} else {
redirectAttributes.addFlashAttribute("error", "记录删除失败!");
}
return "redirect:/lendlist.html";
}
@RequestMapping("/lendbook.html")
public String bookLend(HttpServletRequest request, RedirectAttributes redirectAttributes) {
long bookId = Long.parseLong(request.getParameter("bookId"));
long readerId = ((ReaderCard) request.getSession().getAttribute("readercard")).getReaderId();
if (lendService.lendBook(bookId, readerId)) {
redirectAttributes.addFlashAttribute("succ", "图书借阅成功!");
} else {
redirectAttributes.addFlashAttribute("succ", "图书借阅成功!");
}
return "redirect:/reader_books.html";
}
@RequestMapping("/returnbook.html")
public String bookReturn(HttpServletRequest request, RedirectAttributes redirectAttributes) {
long bookId = Long.parseLong(request.getParameter("bookId"));
long readerId = ((ReaderCard) request.getSession().getAttribute("readercard")).getReaderId();
if (lendService.returnBook(bookId, readerId)) {
redirectAttributes.addFlashAttribute("succ", "图书归还成功!");
} else {
redirectAttributes.addFlashAttribute("error", "图书归还失败!");
}
return "redirect:/reader_books.html";
}
}
运行配置
- 首先安装Mysql5.7,设置用户名为root,密码为root,并保证其在运行状态,并执行library.sql文件导入数据。
- 然后再配置Maven到环境变量中,在源代码目录下运行
mvn jetty:run
- 使用浏览器访问http://localhost:8080即可进入系统。
概念设计
用户分为两类:读者、图书馆管理员。图书馆管理员可以修改读者信息,修改书目信息,查看所有借还日志等;读者仅可以修改个人信息、借阅或归还书籍和查看自己的借还日志。
数据库E-R图
功能展示
1. 首页登陆
2. 管理员系统
用登陆进入
2.1 图书管理
2.2 图书详情
2.3 读者管理
2.4 借还管理
3. 读者系统
3.1 查看全部图书
3.2 个人信息查看,可以修个个人信息
3.3 个人借阅情况查看
标签:教程,bookId,管理系统,request,html,redirectAttributes,新手,addFlashAttribute,图书 来源: https://blog.csdn.net/qq_23034755/article/details/111146181
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。