多条件查询-接收 和记忆查询条件

60 篇文章 1 订阅
9 篇文章 0 订阅

执行查询前:

查询后:
在这里插入图片描述
jsp页面:

<form action="servlet/EmployeeServlet?method=findEmp" method="post">
				<ul class="prosearch">
					<li>
						<label>查询:</label><i>用户名</i>
						<a>
							<input name="empId" type="text" class="scinput" value="${empId }"/>
						</a><i>所属部门</i>
						<a>  <select class="select1" name="deptno">
									<option value="0">--全部--</option>
									<c:forEach items="${deptList }" var="dept">
										<c:if test="${dept.deptno == deptno}">
											<option value="${dept.deptno }" selected="selected">${dept.deptName }</option>
										</c:if>
										<c:if test="${dept.deptno != deptno}">
											<option value="${dept.deptno }">${dept.deptName }</option>
										</c:if>
									</c:forEach>
								</select>
						</a>
									
					</li>
					<li>
						<label>是否在职:</label>
						<c:if test="${onDuty ==1 }">
							<input name="onDuty" type="radio" value="1" checked="checked"/>&nbsp;是&nbsp;&nbsp;
							<input name="onDuty" type="radio" value="0" />&nbsp;否		
						</c:if>
						<c:if test="${onDuty ==0 }">
							<input name="onDuty" type="radio" value="1"  />&nbsp;是&nbsp;&nbsp;
							<input name="onDuty" type="radio" value="0" checked="checked"/>&nbsp;否		
						</c:if>	
						<c:if test="${empty onDuty }">
							<input name="onDuty" type="radio" value="1" checked="checked" />&nbsp;是&nbsp;&nbsp;
							<input name="onDuty" type="radio" value="0" />&nbsp;否		
						</c:if>	
					</li>
					<li>
						<label>入职时间:</label>
						<a>
							<input name="hireDate" type="text" class="scinput" onfocus="WdatePicker()" value="${hireDate} "/>
						</a>		
					</li>
						<a>
							<input name="" type="submit" class="sure" value="查询" />
						</a>
				</ul>
			</form>

servlet实现

	public void findEmp(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//接收查询条件
		String empId = request.getParameter("empId");
		
		int deptno = 0;
		String sdeptno = request.getParameter("deptno"); //null
		try{
			deptno = Integer.parseInt(sdeptno);
		}catch(NumberFormatException e){
			e.printStackTrace();
		}
		int onDuty = 1;
		String sonDuty = request.getParameter("onDuty");//null		
		try{
			onDuty = Integer.parseInt(sonDuty);
		}catch(NumberFormatException e){
			e.printStackTrace();
		}
		String shireDate = request.getParameter("hireDate");//null
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date hireDate = null;
		if(shireDate != null){
			try {
				hireDate = sdf.parse(shireDate);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		
		//调用业务层获取所有的员工信息
		EmployeeService  empService = new EmployeeServiceImpl();
		//List<Employee> empList = empService.findAll();
		//条件如果多,可以封装到一个对象中,使用一个对象做参数
		List<Employee> empList = empService.findEmp(empId,deptno,onDuty,hireDate);
		//获取所有部门的信息
		DepartmentService deptService = new DepartmentServiceImpl();
		List<Department> deptList = deptService.findAll();
		request.setAttribute("deptList", deptList);
		
		//跳转到system/empList.jsp,保存数据,回显到页面输入框中,实现查询记忆功能
		request.setAttribute("empId", empId);
		request.setAttribute("deptno", deptno);
		request.setAttribute("onDuty", onDuty);
		request.setAttribute("hireDate", shireDate);
		request.setAttribute("empList", empList);
		request.getRequestDispatcher("/system/empList.jsp").forward(request, response);
		
	}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值