jsp:select月份时本该做成一个日历格式的,但是能力有限,暂时只能做成现在的这个样子,基本功能算是实现了。
<div id="tb1" style="padding:3px">
<span>月份:</span>
<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>
<span>姓名:</span>
<input type="text" id="usernameSearch" name="usernameSearch" class="easyui-textbox" style="width:100px;">
<span>手机号:</span>
<input type="text" id="phoneSearch" name="phoneSearch" class="easyui-textbox" style="width:150px;">
<span>部门:</span>
<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>
<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:controller:@Override public List<SwipeRecord> selectSwipeRecordByPage(PageBean pageBean, String dName, String username, String test, String phone) { return swipeRecordDao.selectSwipeRecordByPage(pageBean, dName, username, test, phone); }
在查询所有的考勤记录时已经将查询条件传进去了。
/** * 分页 * @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; }