Java项目:图书借阅管理系统(java+SpringBoot+Mybatis+Html+maven+Mysql)

云惠网小编 2021年12月29日17:18:50
评论
5286字阅读17分37秒
摘要

管理员和读者角色功能有:图书管理、借阅管理、读者管理。页面使用的是原生的Jquery,没有使用到Thymeleaf模板引擎,如果想学习的话可以下载下来,可以继续在上面加功能,比如班级管理、学生管理、学院管理、图书馆管理、借阅图书报表等功能。运行环境:jdk1.8、mysql5.x、maven3.5\3.6、idea\eclipse。图书类型服务类:@WebServlet(“/updateBookTypeServlet”)public class updat…

广告也精彩
@WebServlet("/AdminServlet")
public class AdminServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AdminServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//		response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//		doGet(request, response);
PrintWriter out = response.getWriter();
//设置编码类型
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
BookDao bookdao = new BookDao();
//这里为了简单,设置了tip,用来区分是修改密码功能,还是修改个人资料的功能,tip=1为修改密码
int tip = Integer.parseInt(request.getParameter("tip"));
//获取发起请求页面的文件名称,这个在对应的jsp里面的表单填写,修改完成后就可以直接返回对应的页面
String url = request.getParameter("url");
HttpSession session = request.getSession();
AdminBean adminbean = new AdminBean();
//获取存到session的aid
String aid = (String) session.getAttribute("aid");
AdminDao admindao = new AdminDao();
//通过aid获取到读者的信息
adminbean = admindao.get_AidInfo2(aid);
//修改密码
if(tip==1){
//获取到输入的旧密码,新密码
String password = request.getParameter("password");
String password2 = request.getParameter("password2");
//获取读者数据表中的密码
String old_password = adminbean.getPassword();
//对旧密码进行比较,如果相同就修改,不相同就直接退出
if(old_password.equals(password)){
admindao.updateUser(adminbean.getAid(), adminbean.getUsername(), password2, adminbean.getName(),
adminbean.getEmail(), adminbean.getPhone(), adminbean.getLend_num(), adminbean.getMax_num());
response.sendRedirect("/books/"+url+".jsp");
}else{
out.write("<script type='text/javascript'>alert('password error');location.href='"+url+".jsp';  </script>");
}
}else{
//修改个人资料
//获取输入的信息
String name = request.getParameter("name");
String email = request.getParameter("email");
String phone = request.getParameter("phone");
//修改输入的信息到数据表中
admindao.updateUser(adminbean.getAid(), adminbean.getUsername(), adminbean.getPassword(), name,
email, phone, adminbean.getLend_num(), adminbean.getMax_num());
response.sendRedirect("/books/"+url+".jsp");
}
}
}

登录服务类:

 

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public LoginServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//		response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//		doGet(request, response);
//登录的判断
PrintWriter out = response.getWriter();
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
//获取账号和密码
String username = request.getParameter("username");
String password = request.getParameter("password");
AdminDao userdao = new AdminDao();
//对账号和密码进行判断
boolean result = userdao.Login_verify(username, password);
HttpSession session = request.getSession();
//判断输入正确
if(result){
AdminBean adminbean = new AdminBean();
AdminDao admindao = new AdminDao();
//更加账号和密码查找出读者的信息
adminbean = admindao.getAdminInfo(username,password);
//将aid存入session中
session.setAttribute("aid", ""+adminbean.getAid());
//设置session的失效时间
session.setMaxInactiveInterval(6000);
//根据status的值来判断是管理员,还是读者,status=1为读者
if(adminbean.getStatus()==1){
response.sendRedirect("/books/index2.jsp");
}else{
response.sendRedirect("/books/admin.jsp");
}
}else{
//没有找到对应的账号和密码,返回重新登录
session.setAttribute("state", "密码错误");
response.sendRedirect("/books/login.jsp");
}
}
}

图书类型服务类:

管理员和读者角色功能有:图书管理、借阅管理、读者管理。页面使用的是原生的Jquery,没有使用到Thymeleaf模板引擎,如果想学习的话可以下载下来,可以继续在上面加功能,比如班级管理、学生管理、学院管理、图书馆管理、借阅图书报表等功能。

@WebServlet("/updateBookTypeServlet")
public class updateBookTypeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public updateBookTypeServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//		response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//		doGet(request, response);
//修改图书类型信息
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String name = request.getParameter("name");
int tid = Integer.parseInt(request.getParameter("tid"));
TypeDao typedao = new TypeDao();
typedao.updateTypeBook(tid,name);
response.sendRedirect("/books/admin_booktype.jsp");
}
}

 

 

 

运行环境:jdk1.8、mysql5.x、maven3.5\3.6、idea\eclipse。

管理员服务类:

本文转自 https://blog.csdn.net/m0_59687645/article/details/122153760

腾讯云618
未分类
云惠网小编
SpringCloud -- Config、Bus解析

SpringCloud — Config、Bus解析

1、Config1.1、概述简介1. 分布式面临的问题微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中会出现大量的服务。由于每个服务都需要必要...
Java数据结构-了解复杂度

Java数据结构-了解复杂度

2.实例分析与计算  四.写在最后  // 计算斐波那契递归fibonacci的时间复杂度 int fibonacci(int N) { return N < 2 ? N : fibonacci...
[深度解剖C语言] --关键字 static

[深度解剖C语言] –关键字 static

static ---最名不副实的关键字目录1.static修饰全局变量2.static修饰函数3.static修饰局部变量static的作用:1.static修饰全局变量我们创建两...
Java数据结构-认识顺序表

Java数据结构-认识顺序表

目录二.顺序表1.概念及结构2.顺序表的实现打印顺序表获取顺序表的有效长度在pos位置新增元素判断是否包含某个元素查找某个元素对应的位置获取/查找pos位置的元素给pos位置的元素...
腾讯云618

发表评论