javaWeb图书管理系统
1.项目简单介绍
a.项目用到的技术
- IDE: Intellij IDEA
- 语言:java,html + ajax,js
- 数据库:Mysql
- 数据库可视化: navicat
- web服务器:Tomcat
- 框架:(mybatis,jquery,bootstrap)
- 项目用到maven
- 设计模式:MVC
b.该项目的主要功能
- 管理员与普通用户分为不同界面
- 管理员和普通用户可修改个人信息
- 管理员和普通用户注销
- 管理员和普通用户密码(MD5加密)
- 借书,还书操作(并检测还书是否逾期)
- 图书的添加(考虑到图书类型的扩展),修改
- 图书的删除(物理删除和逻辑删除可选)
- 公共图书库查看(分页查询实现)
- 图书查询(多条件和模糊两种)
- 管理员查看用户借书信息,可看是否按时还书
2.项目展示
a. 普通用户功能
(1)查询(多条件和模糊查询)
(2) 个人图书库
(3)用户修改信息界面(有过渡效果)
(4)普通用户界面展示
b . 管理员功能
(1)增加图书
(2)删除图书(物理删除和逻辑删除)
(3)图书修改(回显)
(4)图书查询
(5)查看用户借书记录并查看是否还书逾期
(6)用户管理(逻辑删除)
(7)公共图书库(分页查询)
3.项目讲解
a . 项目基本结构
![Alt]
b . maven导入依赖
<?xml version="1.0" encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>javaWeb_example</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><dependencies><!--jstl--><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><dependency><groupId>taglibs</groupId><artifactId>standard</artifactId><version>1.1.2</version></dependency><!--servlet--><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version><scope>provided</scope></dependency><!--mybatis--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.6</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><!--FASTJSON--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.62</version></dependency><!--密码加密--><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.10</version></dependency><!--HuTool--><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.22</version></dependency></dependencies><!--tomcat插件--><build><plugins><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version><configuration><port>80</port><path>/</path></configuration></plugin></plugins></build></project>
c . 数据库Mysql表
d. javabean中对应的实体类
e . servlet层中的loginservlet(登录后端服务)
packagecom.servlet;importcom.alibaba.fastjson.JSON;importcom.bean.User;importcom.bean.admin;importcom.service.impl.UserServiceImpl;importcom.util.DateAdd;importcom.util.MD5BU;importcom.util.ZhUtils;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.Cookie;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importjava.io.IOException;importjava.text.DateFormat;importjava.text.SimpleDateFormat;importjava.util.Date;importjava.util.List;@WebServlet("/login/*")publicclassLoginServletextendsBaseServlet{privateUserServiceImpl userService =newUserServiceImpl();//登录publicvoidlog(HttpServletRequest req,HttpServletResponse resp)throwsException{HttpSession session = req.getSession();String username = req.getParameter("username");String password = req.getParameter("password");User user = userService.select(username,MD5BU.md5(password));if(user !=null){
user.setPassword(password);
req.setAttribute("isUser",0);
session.setAttribute("user",user);String s = session.getId();Cookie cookie =newCookie("sessionId",s);
cookie.setPath("/");
resp.addCookie(cookie);if(user.root ==1){
resp.sendRedirect("/web_root.jsp");}else{
resp.sendRedirect("http://localhost/web_main.jsp");}}else{
req.setAttribute("isUser",1);
req.getRequestDispatcher("/login.jsp").forward(req,resp);}}//注册publicvoidregister(HttpServletRequest req,HttpServletResponse resp)throwsException{String username = req.getParameter("username");String password = req.getParameter("password");User user = userService.selectOneByUsername(username);if(user !=null){
resp.getWriter().write("true");}else{if(username !=""&& password !=""){
password = MD5BU.md5(password);
userService.register(username,password);
resp.sendRedirect("/login.jsp");}}}//个人图书库publicvoidlibrary(HttpServletRequest req,HttpServletResponse resp)throwsIOException{
req.setCharacterEncoding("utf-8");String username =ZhUtils.getZh(req.getParameter("username"));int userid =Integer.parseInt(req.getParameter("userid"));String bookname =ZhUtils.getZh(req.getParameter("bookname"));int bookid =Integer.parseInt(req.getParameter("bookid"));DateFormat dateFormat =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date =newDate();String dateTime = dateFormat.format(date);String bookAuthor =ZhUtils.getZh(req.getParameter("bookAuthor"));String bookType =ZhUtils.getZh(req.getParameter("bookType"));String date_Hope = dateFormat.format(DateAdd.addDays(date,7));int num =Integer.parseInt(req.getParameter("num"));
userService.usBkConnect(username,userid,bookname,bookid,dateTime,bookAuthor,bookType,date_Hope);
resp.setContentType("text/json;charset=utf-8");
resp.getWriter().write("添加成功~");}//注销publicvoid logout (HttpServletRequest req,HttpServletResponse resp)throwsIOException{
req.getSession().invalidate();
resp.sendRedirect("/login.jsp");}//查询所有管理员publicvoid selectAdminAll (HttpServletRequest req,HttpServletResponse resp)throwsIOException{List<admin> admins = userService.selectAdminAll();String jsonString = JSON.toJSONString(admins);
resp.setContentType("text/json;charset=utf-8");
resp.getWriter().write(jsonString);}}
f . 图书模糊查询功能(ajax)
//模糊查询let blurred_btn = document.getElementById("blurred_btn");let blurredBookName = document.getElementById("seaName");
blurred_btn.onclick=function(){if(blurredBookName.value){axios({
method:"get",
url:"http://localhost/book/blurredQuery?bookName="+blurredBookName.value
}).then(function(resp){let resultBooks = resp.data;createTableSearch(resultBooks);})}else{alert("请填写完整信息!")}}
附上源码 (压缩包大小15.1M)
网盘网址:https://pan.baidu.com/s/1OXURghwGUO40XswrBa8hTA?pwd=aaaa
提取码: aaaa
sql文件: 链接: https://pan.baidu.com/s/1VqC0cwq4pEc8pDwvL4xREA?pwd=aaaa 提取码: aaaa
版权归原作者 蓝色 - Lanse 所有, 如有侵权,请联系我们删除。