客户信息管理系统4—客户信息的查询
2、功能二:客户信息的查询
(1)查询的流程
(2)实现代码
2.1代码组成
index.jsp+ findAllCustomer.jsp+ FindAllServlet +CustomersService + CustomersDao+ CustomersDaoImplement
2.2代码功能介绍
【1】index.jsp:查询入口页面
【2】findAllCustomer.jsp:查询结果显示页面
【3】FindAllServlet:查询客户信息web层
【4】CustomersService :业务层(selectAll方法)
【5】CustomersDao:dao接口层(selectAll方法)
【6】CustomersDaoImplement:dao构造层实现类(selectAll方法)
2.3代码详细
2.3.1 index.jsp:查询入口页面
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path + "/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'index.jsp' starting page</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!--
- <link rel="stylesheet" type="text/css" href="styles.css">
- -->
- </head>
- <body>
- <a href="/customer_system/addCustomer.jsp">添加客户信息</a><br/>
- <a href="/customer_system/FindAllServlet">查询所有客户信息</a><br/>
- <a href="/customer_system/PageQueryServlet?currentPage=1">查询第一页的客户信息</a><br/>
- </body>
- </html>
复制代码 2.3.2 findAllCustomer.jsp:查询结果显示页面
2.3.3 FindAllServlet:查询客户信息web层
- package com.zhku.jsj144.zk.web;
- import java.io.IOException;
- import java.util.List;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.zhku.jsj144.zk.service.CustomersService;
- public class FindAllServlet extends HttpServlet {
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- //查询所有用户信息
- req.setCharacterEncoding("utf-8");//设置编码,防止中文乱码
-
- CustomersService customerService=new CustomersService();//业务层对象
- List resultList=customerService.selectAll();//查询结果集
- ///保管查询结果,转发到客户信息查询显示页面
- req.setAttribute("CustomersList", resultList);
- req.getRequestDispatcher("/findAllCustomer.jsp").forward(req, resp);//转发到查询客户信息页面
- }
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- doPost(req, resp);
- }
-
- }
复制代码 2.3.4 CustomersService :业务层(selectAll方法)
详细看功能一代码实现,已经写好了
2.3.5 CustomersDao:dao接口层(selectAll方法)
详细看功能一代码实现,已经写好了
2.3.6 CustomersDaoImplement:dao构造层实现类(selectAll方法)
详细看功能一代码实现,已经写好了
项目详细代码资源:
自己的github项目地址
https://github.com/Forever99/customer_system |