Spring 多條件查詢分頁功能javascript
第一步:Jspcss
<form name="journal_list" id="journal_list" method="get" action="/cooperation/list_cooperation.do">java
<input name="cityId" id="cityId" value="${cityId }" type="hidden" />sql
<input name="smsTypes" id="smsTypes" value="${smsTypes }" type="hidden" />app
<input name="loading" id="loading" value="${loading }" type="hidden" />jsp
<input name="orderBy" id="orderBy" type="hidden"value="${param.orderBy }" />ide
<input name="orderType" id="orderType" type="hidden" value="${param.orderType }" />oop
<input name="filterDateStatus" id="filterDateStatus" type="hidden" value="${param.filterDateStatus }" />this
<table cellspace="0" cellpadding="0" border="0" class="tb_a" width="100%">url
<TR>
<TD colspan="10"><b>當前位置:合做房源管理 - 查詢</b></td>
</TR>
<tr>
<td style="padding-left: 5px; text-align: left" colspan="2">
活動類型:<select name="activityid" id="activityid">
<option value=""> -- </option>
<c:forEach var="ac" items="${activityList}">
<option value="${ac.ACTIVITY_ID }" <c:if test="${ac.ACTIVITY_ID==avid }">selected=selected</c:if>>${ac.ACTIVITY_DESC}</option>
</c:forEach>
</select>
房源編號:<input name="journalId" type="text" id="journalId" value="${journalId}" class="text100" />
姓 名:<input name="agentName" type="text" id="agentName" value="${agentName}" class="text100" />
手機號碼:<input name="phone" type="text" id="phone" value="${phone}" class="text100" />
</td>
</tr>
<tr>
<td style="padding-left: 5px; text-align: left; width: 820px;">
樓盤名:<input name="loupan" type="text" id="loupan" value="${loupan}" class="text100" />
銷售類型:<input type="radio" name="saletypes" id="saletypes" value="R" <c:if test="${saletypes == 'R'}">checked=checked</c:if>/>租房
<input type="radio" name="saletypes" id="saletypes" value="S" <c:if test="${saletypes == 'S'}">checked=checked</c:if>/>售房
區域名:<select name="areaId" id="areaId">
<option value=""> -- </option>
<c:forEach var="area" items="${areaList}">
<option value="${area.AREA_ID }" <c:if test="${param.areaId != '' && param.areaId == area.AREA_ID }">selected="selected"</c:if> >${area.AREA_NAME }</option>
</c:forEach>
</select>
</td>
<td><input type="submit" name="button" id="button" class="button150"
value=" 查 詢 " />
<a href="#" onclick="javascript:reSet();">重置查詢信息</a></td>
</tr>
</table>
<table class="t_b" width="100%" cellpadding="0" cellspacing="0">
<tr>
<th width="4%">
編號
</th>
<th width="8%">
姓名
</th>
<th width="8%">
手機號
</th>
<th width="5%">
樓盤名
</th>
<th width="6%">
區域
</th>
<th width="6%">
售租類型
</th>
<th width="6%">
售價
</th>
<th width="6%">
租價
</th>
<th width="6%">
建築面積
</th>
<th width="12%">
房子信息
</th>
<th width="12%">
圖片
</th>
<th width="12%">
推薦理由
</th>
<th width="12%">
數據操做
</th>
</tr>
<c:choose>
<c:when test="${not empty list && list != ''}">
<c:forEach var="user" items="${list }">
<tr>
<td>
${user.ID }
</td>
<td>
${user.AGENT_NAME}
</td>
<td>
${user.MOBILE_PHONE}
</td>
<td>
${user.ESTATE_NAME}
</td>
<td>
${user.AREA_NAME }
</td>
<td>
${user.SALES_TYPE}
</td>
<td>
${user.SALE_PRICE }
</td>
<td>
${user.RENT_PRICE }
</td>
<td>
${user.BUILT_AREA}
</td>
<td>
${user.JOURNAL_INFO}
</td>
<td>
<img width="80" height="60" src="http://pic.homescn.com/${user.COVER }" />
</td>
<td>
${user.RECOMMEND_REASON}
</td>
<td>
<a href="#" onclick="javascript:doExcute1('${user.ID }',100,'${cityId }');">刪除</a>
<a href="#" onclick="javascript:doExcute1('${user.ID }',0,'${cityId }');">下架</a>
</td>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
<tr align="center">
<td colspan="12" style="height: 150px;border-right:0;">
沒有數據?
<span style="color: red">換條件查詢</span>
</td>
</tr>
</c:otherwise>
</c:choose>
<tr>
<th colspan="16" style="text-align: right">
<c:import url="/common/pager.jsp">
<c:param name="action" value="/cooperation/list_cooperation.do" />
<c:param name="maxPageItems" value="10" />
<c:param name="formName" value="journal_list" />
</c:import>
</th>
</tr>
</table>
</form>
第二步: Action 類中:
public String list_cooperation(){
Map<String,String> map=initCooperactionList();
if(!"loading".equals(getParameter("loading"))){
PageInfo page = cooperationService.getFteCooperatonJournalList(map, this.getOffset(), this.getMaxPageItems());
PageInfo pageInfo=doFormatDate(page);
this.setContextValue("list", pageInfo.getResult());
this.setContextValue("total", pageInfo.getTotal());
this.setContextValue("branchSite", new BranchSiteUtils());
}else{
this.setContextValue("loading","11");
}
this.setCityId("");
return "list_cooperation";
}
public Map<String,String> initCooperactionList(){
Map<String,String> maps=new HashMap<String,String>();
if("".equals(this.getCityId()) || this.getCityId()==null){
maps.put("cityId",getParameter("cityId"));
this.setCityId(getParameter("cityId"));
this.setContextValue("cityId", getParameter("cityId"));
}else{
maps.put("cityId",this.getCityId());
this.setContextValue("cityId", getCityId());
}
setContextValue("cityId", getParameter("cityId"));
maps.put("excelActivityid",getParameter("excelActivityid")==null?"":getParameter("excelActivityid"));
maps.put("activityid",getParameter("activityid")==null?"":getParameter("activityid"));
setContextValue("activityid", getParameter("activityid"));
maps.put("journalId",getParameter("journalId")==null?"":getParameter("journalId"));
setContextValue("journalId", getParameter("journalId")==null?"":getParameter("journalId"));
maps.put("agentName",getParameter("agentName")==null?"":getParameter("agentName"));
setContextValue("agentName", getParameter("agentName"));
maps.put("phone",getParameter("phone")==null?"":getParameter("phone"));
setContextValue("phone", getParameter("phone")==null?"":getParameter("phone"));
maps.put("loupan",getParameter("loupan")==null?"":getParameter("loupan"));
setContextValue("loupan", getParameter("loupan"));
maps.put("saletypes",getParameter("saletypes")==null?"":getParameter("saletypes"));
setContextValue("saletypes", getParameter("saletypes"));
maps.put("areaId",getParameter("areaId")==null?"":getParameter("areaId"));
setContextValue("areaId", getParameter("areaId"));
setContextValue("areaList", this.commonService.loadAreaList(Long.parseLong(getCityId())));
setContextValue("activityList",cooperationService.getCooperationActivity());
String avid=getParameter("activityid");
this.setContextValue("avid",avid);
return maps;
}
第三步: Dao 中
import org.jnv.framework.common.pager.PageInfo;
import org.jnv.framework.dao.BaseSpringJdbcDAO;
public PageInfo getFteCooperatonJournalList(Map map, int begin, int interval) {
PageInfo pageInfo = new PageInfo();
List params = new ArrayList();
StringBuffer sql=new StringBuffer("SELECT ID,AGENT_NAME,MOBILE_PHONE,ESTATE_NAME,AREA_NAME,IF(SALES_TYPE='R','租','售') AS SALES_TYPE,SALE_PRICE,RENT_PRICE,BUILT_AREA,IF(SALES_TYPE='R',CONCAT(BEDROOM_COUNT,'室',SITTINGROOM_COUNT,'廳',TOILET_COUNT,'衛',BALCONY_COUNT,'陽臺'),'') AS JOURNAL_INFO,COVER,RECOMMEND_REASON FROM FTE_COOPERATION_JOURNAL WHERE STATUS=1");
StringBuffer sqlcount=new StringBuffer("SELECT COUNT(*) FROM FTE_COOPERATION_JOURNAL WHERE STATUS=1");
if(StringUtils.isNotEmpty(map.get("cityId").toString())){
sql.append(" AND CITY_ID=?");
sqlcount.append(" AND CITY_ID=?");
params.add(map.get("cityId"));
}
if(StringUtils.isNotEmpty(map.get("journalId").toString())){
sql.append(" AND ID=?");
sqlcount.append(" AND ID=?");
params.add(map.get("journalId"));
}
if(StringUtils.isNotEmpty(map.get("agentName").toString())){
sql.append(" AND AGENT_NAME=?");
sqlcount.append(" AND AGENT_NAME=?");
params.add(map.get("agentName"));
}
if(StringUtils.isNotEmpty(map.get("phone").toString())){
sql.append(" AND MOBILE_PHONE=?");
sqlcount.append(" AND MOBILE_PHONE=?");
params.add(map.get("phone"));
}
if(StringUtils.isNotEmpty(map.get("loupan").toString())){
sql.append(" AND ESTATE_NAME=?");
sqlcount.append(" AND ESTATE_NAME=?");
params.add(map.get("loupan"));
}
if(StringUtils.isNotEmpty(map.get("areaId").toString())){
sql.append(" AND AREA_ID=?");
sqlcount.append(" AND AREA_ID=?");
params.add(map.get("areaId"));
}
if(StringUtils.isNotEmpty(map.get("activityid").toString())){
sql.append(" AND ACTIVITY_ID=?");
sqlcount.append(" AND ACTIVITY_ID=?");
params.add(map.get("activityid"));
}
if(StringUtils.isNotEmpty(map.get("saletypes").toString())){
sql.append(" AND SALES_TYPE=?");
sqlcount.append(" AND SALES_TYPE=?");
params.add(map.get("saletypes"));
}
sql.append(" ORDER BY ID DESC");
System.out.println(sql.toString());
int total = this.baseSpringJdbcDAO.getJdbcTemplate().queryForInt(sqlcount.toString(), params.toArray());
pageInfo.setTotal(total);
if (total > 0) {
List<Map> list = this.baseSpringJdbcDAO.getJdbcTemplate().queryForList(sql.toString() + " LIMIT " + begin + ", " + interval, params.toArray());
pageInfo.setResult(list);
}else{
pageInfo.setResult(new ArrayList());
}
return pageInfo;
}