SSM实现多条件查询

jsp:select月份时本该做成一个日历格式的,但是能力有限,暂时只能做成现在的这个样子,基本功能算是实现了。

<div id="tb1" style="padding:3px">
	<span>月份:</span>&nbsp;
	<select id="monthSearch" name="monthSearch" class="easyui-combobox" editable="false" panelheight="auto" style="width: 70px;"> 
	<option value=""></option>
	<option value="1">一月</option>
	<option value="2">二月</option>
	<option value="3">三月</option>
	<option value="4">四月</option>
	<option value="5">五月</option>
	<option value="6">六月</option>
	<option value="7">七月</option>
	<option value="8">八月</option>
	<option value="9">九月</option>
	<option value="10">十月</option>
	<option value="11">十一月</option>
	<option value="12">十二月</option></select>&nbsp;&nbsp;
	<span>姓名:</span>&nbsp;
	<input type="text" id="usernameSearch" name="usernameSearch" class="easyui-textbox" style="width:100px;">&nbsp;&nbsp;
	<span>手机号:</span>&nbsp;
	<input type="text" id="phoneSearch" name="phoneSearch" class="easyui-textbox" style="width:150px;">&nbsp;&nbsp;
	<span>部门:</span>&nbsp;
	<select id="departmentSearch" name="departmentSearch" class="easyui-combobox" editable="false" panelHeight="auto" style="width:100px;" data-options="valueField:'dId',textField:'dName',url:'${pub }/webDepartment/listAllDepartment'">
   	</select>&nbsp;
	<a href="#" class="easyui-linkbutton" plain="false" οnclick="doSearch()">查询</a>
	<a href="#" class="easyui-linkbutton" plain="false" οnclick="reset()">重置条件</a>
</div>

js:
 function doSearch(){
		$('#dg').datagrid('reload',{
			test:$('#monthSearch').combobox('getValue'),
			username:$('#usernameSearch').textbox('getValue'),
			phone:$('#phoneSearch').textbox('getValue'),
			dName:$('#departmentSearch').combobox('getText')
		})
	
dao:

	<!-- 分页查询 -->
	<select id="selectSwipeRecordByPage" resultMap="BaseResultMaps">
		select r.id,u.username ,r.card_type,d.d_name,r.swipe_time,r.phone
		from all_swipe_record r
		inner join user u on r.phone=u.phone
		inner join department d on u.department_id=d.d_id 
		  <where>
			<if test="phone!=null and phone!='' ">
				and r.phone like "%"#{phone}"%"
			</if>
			<if test="test!=null and test!='' ">
				and month(swipe_time)=#{test}
			</if>
			<if test="dName!=null  and dName!=''">
				and d.d_name like "%"#{dName}"%"
			</if>
			<if test="username!=null and username!=''">
				and u.username like "%"#{username}"%"
			</if>
			</where> 
		ORDER BY u.username
		limit #{pageBean.start},#{pageBean.pageSize} 
	</select>

mapper.xml  查询语句多看多练
		<select id="selectSwipeRecordByPage" resultMap="BaseResultMaps">
		select r.id,u.username ,r.card_type,d.d_name,r.swipe_time,r.phone
		from all_swipe_record r
		inner join user u on r.phone=u.phone
		inner join department d on u.department_id=d.d_id 
		  <where>
			<if test="phone!=null and phone!='' ">
				and r.phone like "%"#{phone}"%"
			</if>
			<if test="test!=null and test!='' ">
				and month(swipe_time)=#{test}
			</if>
			<if test="dName!=null  and dName!=''">
				and d.d_name like "%"#{dName}"%"
			</if>
			<if test="username!=null and username!=''">
				and u.username like "%"#{username}"%"
			</if>
			</where> 
		ORDER BY u.username
		limit #{pageBean.start},#{pageBean.pageSize} 
	</select>

service:

	/**
	 * 传入所有要查询的条件作为参数
	 * @param phone
	 * @param test
	 * @return
	 */
	
	public List<SwipeRecord> selectSwipeRecordByPage(PageBean pageBean, String dName, String username, String test, String phone) ;


serviceImpl:
	@Override
	public List<SwipeRecord> selectSwipeRecordByPage(PageBean pageBean,
			String dName, String username, String test, String phone) {
		
		return swipeRecordDao.selectSwipeRecordByPage(pageBean, dName, username, test, phone);
	}
controller:

在查询所有的考勤记录时已经将查询条件传进去了。

	/**
	 * 分页
	 * @param pageNow
	 * @return
	 */
	@RequestMapping(value = "/swipeRecordByPage" , method = RequestMethod.POST)
	@ResponseBody
	public JSONObject swipeRecordByPage(@RequestParam(value="page",required=false)String page,@RequestParam(value="rows",required=false)String rows,String dName, String username, String test, String phone,HttpServletResponse response){
		JSONObject result = new JSONObject();
		try {
			
			PageBean pageBean=new PageBean(Integer.parseInt(page),Integer.parseInt(rows));
			List<SwipeRecord> swipeRecordList = swipeRecordService.selectSwipeRecordByPage(pageBean, dName, username, test, phone);
			Long total = swipeRecordService.selectSwipeRecordCount();
			
			result.put("rows", swipeRecordList);
			result.put("total", total);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return  result;
	}



  • 9
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值