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:
@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;
}