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

Posted qq_1334611189

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java项目:图书借阅管理系统(java+SpringBoot+Mybatis+Html+maven+Mysql)相关的知识,希望对你有一定的参考价值。

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

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

 

 

 

 

图书类型服务类:

@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");
	


登录服务类:

@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");
		
	


管理员服务类:

@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");
		
	


以上是关于Java项目:图书借阅管理系统(java+SpringBoot+Mybatis+Html+maven+Mysql)的主要内容,如果未能解决你的问题,请参考以下文章

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

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

Java小项目迷你图书管理系统

图书借阅和归还管理java系统源码/图书馆管理必备系统

用java编写一个 图书馆图书借阅管理系统

基于Java+Spring+Html的图书借阅管理系统详细设计和实现