您的位置:首页 > 其它

客户信息管理系统8—客户信息的模糊查询

2017-10-18 17:50 429 查看
客户信息管理系统8—客户信息的模糊查询

5、功能五:模糊查询(条件查询)

(1)条件查询说明

条件查询:需要 用户去选择按照什么条件查询, 以及查询的具体的值

一般条件 可以由用户选择



在服务器端 根据用户选定的条件,进行where语句封装

举例:

根据 name, 手机号, 描述去查询.

select * fromusers where name like  ‘%何%’;

注意:条件字段不同,查询逻辑可能会不同

(2)查询需求分析

1、下拉列表时条件,输入框是关键字,即:条件+关键字,进行条件查询

2、考虑sql语句的写法,进行拼接sql语句进行查询

数据库中查询:select * from users where namelike  ‘%何%’;

条件:name+关键字:何)

java代码中:List customersList=qr.query("select *from customers where "+conditionName+" like ?", newBeanListHandler(Customers.class),

"%"+keyWords+"%");

3、回显查询条件,以及查询关键字在findAllCustomer.jsp上

利用el表达式的param来获取request传递过来的参数

eg:       条件:${param.conditionName=='name' }

关键字:${param.keyWords }

(3)代码组成

findAllCustomer.jsp+ SelectConditionServlet+

CustomersService  +  CustomersDao +  CustomersDaoImplement

(3)代码功能介绍

【1】findAllCustomer.jsp:查询结果显示页面,条件查询客户信息的入口

【2】SelectConditionServlet:条件查询的客户信息的web层

【3】CustomersService :业务层

(selectCondition(conditionName,keyWords)方法)

【4】CustomersDao:dao接口层

(selectCondition(conditionName,keyWords)方法)

【5】CustomersDaoImplement:dao结构层实现类

(selectCondition(conditionName,keyWords)方法)

 

(4)代码详细

5.4.1 findAllCustomer.jsp:查询结果显示页面,条件查询客户信息的入口
详细看功能二代码实现,已经写好了

5.4.2 SelectConditionServlet:条件查询的客户信息的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 SelectConditionServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

//解决乱码问题
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("text/html;charset=utf-8");

//条件查询
//条件:conditionName 关键字:keyWords
String conditionName=request.getParameter("conditionName");//查询条件
String keyWords=request.getParameter("keyWords");//查询关键字

CustomersService customersService=new CustomersService();
List customersList=customersService.selectCondition(conditionName,keyWords);

//保存查询结果,并显示在查询结果页面上
request.setAttribute("CustomersList", customersList);
request.getRequestDispatcher("/findAllCustomer.jsp").forward(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doGet(request, response);

}

}
5.4.3 CustomersService :业务层-----------------------------(selectCondition(conditionName,keyWords)方法)
详细看功能一代码实现,已经写好了

 

5.4.4 CustomersDao:dao接口层-----------------------------(selectCondition(conditionName,keyWords)方法)
详细看功能一代码实现,已经写好了

 

5.4.5 CustomersDaoImplement:dao结构层实现类--------------------------(selectCondition(conditionName,keyWords)方法)
详细看功能一代码实现,已经写好了

 项目详细代码资源:

本人的github项目地址
https://github.com/Forever99/customer_system
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: