12.17
图书信息管理系统(使用layui)
底层的service和servlet层的代码:
package service; import bean.dao; import bean.info; import java.util.ArrayList; import java.util.List; public class Service { static dao dao=new dao(); public static boolean add(info activity) { // TODO 自动生成的方法存根 if(dao.findISBN(activity.getISBN())==true) { System.out.print("已有此图书信息"); return false; } else{ dao.add(activity); return true; } } public static List<info> list() { return dao.getAllinformation(); } }
package servlet; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import bean.dao; import bean.info; import service.Service; /** * Servlet implementation class Servlet */ @WebServlet("/Servlet") public class Servlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public Servlet() { 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 request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); info webactivity=new info(); Service service=new Service(); String author = request.getParameter("author"); String ISBN = request.getParameter("ISBN"); String banname=request.getParameter("banname"); String category=request.getParameter("category"); String introduction=request.getParameter("introduction"); String evaluate=request.getParameter("evaluate"); String method=request.getParameter("method"); System.out.println(ISBN); webactivity.setAuthor(author); webactivity.setISBN(ISBN); webactivity.setBanname(banname); webactivity.setCategory(category); webactivity.setIntroduction(introduction); webactivity.setEvaluate(evaluate); if("add".equals(method)) { if(Service.add(webactivity)) { System.out.print("添加成功"); List<info> activity11=Service.list(); request.setAttribute("activity11",activity11); request.setAttribute("message", "添加成功"); request.getRequestDispatcher("message.jsp").forward(request,response); } else { System.out.println("添加失败"); request.setAttribute("message", "添加失败,请重新添加"); request.getRequestDispatcher("message.jsp").forward(request,response); } } if("del".equals(method)) { dao sd=new dao(); try{ sd.delete(ISBN); System.out.println("listshow"); request.getRequestDispatcher("delete.jsp").forward(request, response); }catch(Exception e){ System.out.println("未能正确显示出图书信息"); e.printStackTrace(); } } if("update".equals(method)) { dao sd=new dao(); try{ sd.update(webactivity); System.out.println("listshow"); request.getRequestDispatcher("update.jsp").forward(request, response); }catch(Exception e){ System.out.println("未能正确显示出图书信息"); e.printStackTrace(); } } if("show".equals(method)) { dao sd=new dao(); try{ java.util.List<info> list=sd.getAllinformation(); request.setAttribute("list", list); System.out.println("listshow"); request.getRequestDispatcher("show.jsp").forward(request, response); }catch(Exception e){ System.out.println("未能正确显示出图书信息"); e.printStackTrace(); } } if("select".equals(method)) { dao sd=new dao(); try{ java.util.List<info> list=sd.select(ISBN); request.setAttribute("list", list); System.out.println("listshow"); request.getRequestDispatcher("delete.jsp").forward(request, response); }catch(Exception e){ System.out.println("未能正确显示出图书信息"); e.printStackTrace(); } } if("select1".equals(method)) { dao sd=new dao(); try{ java.util.List<info> list=sd.select(ISBN); request.setAttribute("list", list); System.out.println("listshow"); request.getRequestDispatcher("update.jsp").forward(request, response); }catch(Exception e){ System.out.println("未能正确显示出图书信息"); e.printStackTrace(); } } if("jisuanji".equals(method)) { dao sd=new dao(); try{ java.util.List<info> list=sd.jisuanji(); System.out.println(123); request.setAttribute("list", list); System.out.println("listshow"); request.getRequestDispatcher("show.jsp").forward(request, response); }catch(Exception e){ System.out.println("未能正确显示出图书信息"); e.printStackTrace(); } } if("renwen".equals(method)) { dao sd=new dao(); try{ java.util.List<info> list=sd.renwen(); System.out.println(123); request.setAttribute("list", list); System.out.println("listshow"); request.getRequestDispatcher("show.jsp").forward(request, response); }catch(Exception e){ System.out.println("未能正确显示出图书信息"); e.printStackTrace(); } } if("ziran".equals(method)) { dao sd=new dao(); try{ java.util.List<info> list=sd.ziran(); System.out.println(123); request.setAttribute("list", list); System.out.println("listshow"); request.getRequestDispatcher("show.jsp").forward(request, response); }catch(Exception e){ System.out.println("未能正确显示出图书信息"); e.printStackTrace(); } } if("tianwen".equals(method)) { dao sd=new dao(); try{ java.util.List<info> list=sd.tianwen(); System.out.println(123); request.setAttribute("list", list); System.out.println("listshow"); request.getRequestDispatcher("show.jsp").forward(request, response); }catch(Exception e){ System.out.println("未能正确显示出图书信息"); e.printStackTrace(); } } //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); } }
至此,一个简单的图书管理系统就使用layui全部完成。