先来看看我们所要填写的查询条件代码:
<label> 时间: 从
<input name="startTime" id="startdate" type="text" /> 到
</label>
<label>
<input name="endTime" id="enddate" type="text" />
</label>
<label> 状态:
<select name="state" id="state">
<option value="1">已出发</option>
<option value="2">等待中</option>
<option value="3">未出发</option>
</select>
</label>
<label> 手机号:
<input name="CPhone" id="receivePhone" type="text" />
</label>
<label> 编号:
<input id="sellerCode" name="cbNo" class="form-control input-sm" type="text" />
</label>
<input type="submit" value="查找" οnclick="submitForm2()" />
JS代码:
function startRequest2(pageNo) {
//根据id取得填写条件的值
var startTime = document.getElementById("startdate").value; //开始时间
var endTime = document.getElementById("enddate").value; //结束时间
var state = document.getElementById("state").value; //状态
var CPhone = document.getElementById("receivePhone").value; //手机号
xmlHttp2.onreadystatechange = function() { //回调函数
handleStateChange2();
};
xmlHttp2.open("POST","pointInOrderAction!findCountAgencyOrders",true); //请求地址,true表示开启异步
xmlHttp2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp2.send("page.currentPage=" + pageNo + "&startTime=" + startTime + "&endTime="+endTime + "&state="+state"+"&CPhone="+CPhone); //发送请求参数,action中setget即可取到
}
JS代码:
var xmlHttp2 = getXmlHttpRequest();<span style="white-space:pre"> </span> <span style="color: rgb(0, 130, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; ">//创建Ajax核心对象XMLHttpRequest</span> function handleStateChange2() { if (xmlHttp2.readyState == 4) { <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: rgb(248, 248, 248); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; ">//Ajax引擎状态为成功</span><span style="margin: 0px; padding: 0px; border: none; background-color: rgb(248, 248, 248); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; "> </span>
if (xmlHttp2.status == 200) { <span style="color: rgb(0, 130, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; background-color: rgb(248, 248, 248); ">//HTTP协议状态为成功</span>
var text = (xmlHttp2.responseText);
var jsonObj = eval('(' + text + ')');
var jsonObject = JSON.parse(text);
var teamTable = document.getElementById("teamTable");
//清除原有数据
for ( var i = teamTable.rows.length - 1; i > 0; i--) {
teamTable.deleteRow(i);
}
//处理页面跳转的连接
var pageDiv = document.getElementById("page") ;//处理分页显示
var pageTotal = jsonObject.pageInfo.pageTotal ;
var currentPage=jsonObject.pageInfo.currentPage ;
var pageNo=jsonObject.pageInfo.currentPage ;
var totalCount=jsonObject.pageInfo.totalCount; //处理分页显示
for(var i=0;i<jsonObject.AgencyOrderList.length;i++) {
//为表格加一行
var tr = teamTable.insertRow(i+1);
//tr.className="exist-address-list";
//为表格加一个格
var td = tr.insertCell(0);
td.innerHTML = jsonObject.AgencyOrderList[i].uname;
//为表格加一个格
var td = tr.insertCell(1);
td.innerHTML =jsonObject.AgencyOrderList[i].piaoCPhone;
//为表格加一个格
var td = tr.insertCell(2);
td.innerHTML =jsonObject.AgencyOrderList[i].Pointname;
//为表格加一个格
var td = tr.insertCell(3);
td.innerHTML = jsonObject.AgencyOrderList[i].cename + "/" + jsonObject.AgencyOrderList[i].deliveryNo;
//为表格加一个格
var td = tr.insertCell(7);
td.innerHTML = jsonObject.AgencyOrderList[i].updateTime;
}
var pageHtml =" ";
pageHtml +=("<EM> "+pageNo+"/"+pageTotal+"页</EM> 共"+totalCount+"条记录");
if(pageNo<=1){
pageHtml +=("<EM>首页</EM><EM>上一页</EM>");
}
if(pageNo>1){
pageHtml += "<a href='javascript:startRequest2("+ 1 +")'>首页</a> " ; //可以改为上一页 "1" 改为: (pageNo-1)
pageHtml += "<a href='javascript:startRequest2("+ (pageNo-1) +")'>上一页</a> " ;
}
if(pageTotal<=10){
for(i = 0 ; i < pageTotal; i++){
if((i+1)==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(i+1)+")'>"+(i+1)+"</a>";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(i+1)+")'>"+(i+1)+"</a>";
}
}
}
else{
if(currentPage<=3){
if(1==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(1)+")'>"+(1)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(1)+")'>"+(1)+"</a> ";
}
if(2==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(2)+")'>"+(2)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(2)+")'>"+(2)+"</a> ";
}
if(3==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(3)+")'>"+(3)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(3)+")'>"+(3)+"</a> ";
}
if(4==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(4)+")'>"+(4)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(4)+")'>"+(4)+"</a> ";
}
pageHtml += "....";
if(pageTotal==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(pageTotal)+")'>"+(pageTotal)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(pageTotal)+")'>"+(pageTotal)+"</a>";
}
}
else if((pageTotal-3)> currentPage&¤tPage>= 4){
pageHtml += "....";
pageHtml += "<a href = 'javascript:startRequest2("+(currentPage-2)+")'>"+(currentPage-2)+"</a> ";
pageHtml += "<a href = 'javascript:startRequest2("+(currentPage-1)+")'>"+(currentPage-1)+"</a> ";
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(currentPage)+")'>"+(currentPage)+"</a> ";
pageHtml += "<a href = 'javascript:startRequest2("+(currentPage+1)+")'>"+(currentPage+1)+"</a> ";
pageHtml += "<a href = 'javascript:startRequest2("+(currentPage+2)+")'>"+(currentPage+2)+"</a> ";
pageHtml += "....";
}
else if(currentPage>=(pageTotal-3)){
pageHtml += "....";
if(pageTotal-4==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(pageTotal-4)+")'>"+(pageTotal-4)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(pageTotal-4)+")'>"+(pageTotal-4)+"</a> ";
}
if(pageTotal-3==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(pageTotal-3)+")'>"+(pageTotal-3)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(pageTotal-3)+")'>"+(pageTotal-3)+"</a> ";
}
if(pageTotal-2==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(pageTotal-2)+")'>"+(pageTotal-2)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(pageTotal-2)+")'>"+(pageTotal-2)+"</a> ";
}
if(pageTotal-1==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(pageTotal-1)+")'>"+(pageTotal-1)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(pageTotal-1)+")'>"+(pageTotal-1)+"</a> ";
}
if(pageTotal==currentPage){
pageHtml += "<a class='h-highlight' href = 'javascript:startRequest2("+(pageTotal)+")'>"+(pageTotal)+"</a> ";
}
else{
pageHtml += "<a href = 'javascript:startRequest2("+(pageTotal-4)+")'>"+(pageTotal)+"</a> ";
}
}
}
if(pageNo < pageTotal) {
pageHtml += "<a href='javascript:startRequest2("+ (pageNo+1) +")'>下一页 </a> " ;
pageHtml += " <a href='javascript:startRequest2(" + pageTotal + ")'>尾页</a>"; //可以改为下一页 pageTotal 改为: (pageNo+1)
}
if(pageNo==pageTotal){
pageHtml +=("<EM>下一页</EM><EM>尾页</EM>");
}
pageDiv.innerHTML = pageHtml ;
}
}
}
java代码:
public void findCountAgencyOrders() throws Exception{
HttpServletResponse response = ServletActionContext.getResponse();
if(currpage>0)
{
Result res = Service.findOrders(page,CPhone,cbNo, state,startTime, endTime);//根据条件查询数据库
page=res.getPage();
// 如果当前页大于总页数,则当前页减1或当前页设为总页数
if(currpage>page.getTotalPage())
{
page.setCurrentPage(page.getTotalPage());
}
else
{
page.setCurrentPage(currpage);
}
currpage=0;
}
Result res = Service.findOrders(page,CPhone, cbNo, state,startTime, endTime);
page=res.getPage();
List teams =res.getList();
try {
response.setContentType("text/html;charset=UTF-8");
response.getWriter().println(JsonUtil.JsonPage(teams, page));
} catch (IOException e) {
e.printStackTrace();
}
}
public static Object zsAgencyOrderlistToJsonPage(List AgencyOrderList,Page pageInfo) {
String jsonStr = null;
StringBuffer strBuffer = new StringBuffer();
strBuffer.append("{");
//strBuffer.append("\"pointRechargeRecordList\":[");
strBuffer.append("\"AgencyOrderList\":[");
//处理pointRechargeRecordList
for(int i=0;i<AgencyOrderList.size();i++)
{
Object[] temp = (Object[]) AgencyOrderList.get(i);
//temp开始
strBuffer.append("{");
//处理手机号
strBuffer.append("\"piaoCPhone\":\"");
strBuffer.append((String)temp[1]);
strBuffer.append("\",");
//状态
strBuffer.append("\"piosName\":\"");
strBuffer.append((String)temp[6]);
strBuffer.append("\",") ;
//更新时间
strBuffer.append("\"updateTime\":\"");
strBuffer.append((String)temp[8]);
strBuffer.append("\"") ;
//team结束
if(i<AgencyOrderList.size()-1)
{
strBuffer.append("},");
}
else
{
strBuffer.append("}");
}
}
//golddetaillist结束
strBuffer.append("],");
//pageInfo开始
strBuffer.append("\"pageInfo\":{");
//处理pageRows
strBuffer.append("\"pageRows\":");
strBuffer.append(pageInfo.getEveryPage());
strBuffer.append(",");
//处理currentPage
strBuffer.append("\"currentPage\":");
strBuffer.append(pageInfo.getCurrentPage());
strBuffer.append(",");
//处理totalCount
strBuffer.append("\"totalCount\":");
strBuffer.append(pageInfo.getTotalCount());
strBuffer.append(",");
//处理pageTotal
strBuffer.append("\"pageTotal\":");
strBuffer.append(pageInfo.getTotalPage());
//pageInfo结束
strBuffer.append("}");
//json结束
strBuffer.append("}");
jsonStr = strBuffer.toString();
return jsonStr;
}
jsp显示结果表头代码:
<table id="teamTable" class="bussiness_center" cellpadding="0" cellspacing="0">
<tr style="font-weight: bold;">
<th>
收件人手机号
</th>
<th>
状态
</th>
<th>
类型
</th>
<th>
更新时间
</th>
</tr>
</table>
<div id="page"></div>
望加指点。