天天看点

客户信息管理系统4—客户信息的查询

客户信息管理系统4—客户信息的查询

2、功能二:客户信息的查询

(1)查询的流程

客户信息管理系统4—客户信息的查询

(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%>" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" >

<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" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" >
	-->
</head>

<body>

<a href="/customer_system/addCustomer.jsp" target="_blank" rel="external nofollow" >添加客户信息</a><br/>
<a href="/customer_system/FindAllServlet" target="_blank" rel="external nofollow" >查询所有客户信息</a><br/>
<a href="/customer_system/PageQueryServlet?currentPage=1" target="_blank" rel="external nofollow" >查询第一页的客户信息</a><br/>
</body>
</html>
           
2.3.2 findAllCustomer.jsp:查询结果显示页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	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%>" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" >

<title>My JSP 'findAllCustomer.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" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" >
	-->

<script>
	//删除确认对话框
	function confirm_deleteOne(id) {
// 	alert(id);
    var message=confirm("你确定要删除这条记录吗?");
    if(message==true){
    	
//     	window.location("/customer_system/DeleteOneServlet?id="+id);//错误【使用错误,是等号=,不是括号()】
// 		window.location="/customer_system/DeleteOneServlet?id="+id;//正确

//     	document.location.herf="/customer_system/DeleteOneServlet?id="+id;//错误[拼写错误]
		window.location.href="/customer_system/DeleteOneServlet?id=" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" +id;//正确
// 		document.location.href="/customer_system/DeleteOneServlet?id=" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" +id;//正确
//     	document.location="/customer_system/DeleteOneServlet?id="+id;//正确
    }
	}
	
	//全选或者全不选
	function checkAll(){
		//id="chooseFirst"  如果选中,下面的checkbox全部被选中
		var chooseAll=document.getElementsByName("choose");//全部choose
		var choose=document.getElementById("chooseFirst");//第一个choose
		//选中状态:checked可以为true或者false
		if(choose.checked){
			for(var i=0;i<chooseAll.length;i++){
			 	chooseAll[i].checked=true;
			}
		
		}		
		//id="chooseFirst"  如果没有选中,下面的checkbox全部不选中
		else{
			for(var i=0;i<chooseAll.length;i++){
				 	chooseAll[i].checked=false;
				}
		}
	}
</script>
</head>

<body>
	<h1 align="center">客户信息查询列表</h1>
	<form action="/customer_system/SelectConditionServlet" method="post"> 
	<table align="center">
	<tr>
	<td>
	<select name="conditionName">
	<option value="name"
	<c:if test="${param.conditionName=='name' }">
	selected="selected"
	</c:if>
	>按姓名查询</option>
	<option value="cellphone"
	<c:if test="${param.conditionName=='cellphone' }">
	selected="selected"
	</c:if>
	>按手机号码查询</option>
	<option value="description"
	<c:if test="${param.conditionName=='description' }">
	selected="selected"
	</c:if>
	>按描述查询</option>
	</select>
	</td>
	<td><input type="text" name="keyWords" value="${param.keyWords }"></td>
	<td><input type="submit" value="查询"></td>
	</tr>
	</table>
	</form>

	<form action="/customer_system/DeleteAllServlet" method="post"> 
	
	<table  align="center">
		<tr>
			<!--     <td>编号</td> -->
			<td>选中状态<input type="checkbox" name="choose" id="chooseFirst" οnclick="checkAll()"></td>
			<td>客户姓名</td>
			<td>性别</td>
			<td>生日</td>
			<td>手机</td>
			<td>电子邮件</td>
			<td>客户爱好</td>
			<td>客户类型</td>
			<td>备注</td>
			<td>状态</td>
		</tr>


		<c:forEach var="customer" items="${CustomersList }">
			<tr>
				<!--     <td>${customer.id }</td> -->
				<td><input type="checkbox" name="choose" value="${customer.id }"></td>
				<td>${customer.name }</td>
				<td>${customer.gender }</td>
				<td>${customer.birthday }</td>
				<td>${customer.cellphone }</td>
				<td>${customer.email }</td>
				<td>${customer.preference }</td>
				<td>${customer.type }</td>
				<td>${customer.description }</td>
				<!--     <td><a href="/customer_system/DeleteOneServlet?id=${customer.id }" target="_blank" rel="external nofollow" >删除</a></td> -->
				<td><a href="javascript:void(0)" target="_blank" rel="external nofollow"  οnclick="confirm_deleteOne('${customer.id}')">删除</a>
					<a href="/customer_system/GetUpdateInfoServlet?id=${customer.id }" target="_blank" rel="external nofollow" >修改</a>
					</td>
			</tr>
		</c:forEach>


	</table>
	<div align="center"><input type="submit" value="多选删除提交按钮" ></div>
	</form> 
</body>
</html>
           
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

继续阅读