翻页按钮
controller
String company = getParameter(request, "company");
modelMap.addAttribute("company", company);
String id1 = getParameter(request, "id");
modelMap.addAttribute("id", id1);
modelMap.addAttribute("close", close);
//得到分类
//当前页
int pageID = getIntParameter(request, "pageID");
int id = getIntParameter(request, "id");
modelMap.addAttribute("id", id);
EnnOrgOemModel org = ennOrgOemService.selectByPrimaryKey(getIntParameter(request, "id"));
modelMap.addAttribute("ennOrgOemModel", org);
//得到总数量
int user2orgCount = ennUser2PacdService.selectCountByString("SELECT count(*) FROM ennuser2pacd WHERE companyOemID =" + id + " AND isSave = '1'");
//分页Model
PagingModel paging = new PagingModel(pageID, 20, user2orgCount);
paging.openPaging(modelMap, request);//开启分页
//得到分类
// 创建返回列表
List<Map<String, Object>> chooseList = new ArrayList<Map<String, Object>>();
// 首先得到选择的用户
// String u2psql = "SELECT * FROM ennuser2pacd WHERE companyOemID =" + id + " AND isSave = '1' ORDER BY modifyTime DESC LIMIT "+paging.getBeginID()+","+paging.getOnePageItemCount();
String u2psql = "SELECT * FROM ennuser2pacd WHERE companyOemID =" + id + " ORDER BY modifyTime DESC LIMIT "+paging.getBeginID()+","+paging.getOnePageItemCount();
List<EnnUser2PacdModel> u2pList = ennUser2PacdService.selectBySql(u2psql);
if (!u2pList.isEmpty()) {
Map<String, Object> map = null;
for (EnnUser2PacdModel forModel : u2pList) {
map = new HashMap<String, Object>();
map.put("id", forModel.getId());
map.put("name", forModel.getName());
map.put("referralcode", forModel.getReferralcode());
map.put("sex", forModel.getSex());
map.put("education", forModel.getEducation());
map.put("isSave", forModel.getIsSave());
map.put("companyOemID", forModel.getCompanyOemID());
String u2osql = "SELECT * FROM ennuser2org WHERE userSystemID = '" + forModel.getUserID() + "' AND version = '"
+ forModel.getCompanyOemID() + "'";
List<EnnUser2OrgModel> u2oList = ennUser2OrgService.selectBySql(u2osql);
// 如果不止一条记录,就不作修改,让用户自行选择
u2osql = "SELECT * FROM ennuser2org WHERE userSystemID = '" + forModel.getUserID() + "' AND version = '"
+ forModel.getCompanyOemID() + "' AND isChoose='"+1+"'";
u2oList = ennUser2OrgService.selectBySql(u2osql);
if (!u2oList.isEmpty()) {
EnnUser2OrgModel u2o = u2oList.get(0);
EnnRepaTestPaperModel rtp = ennRepaTestPaperService.selectByPrimaryKey(u2o.getTestResultID());
if (rtp != null) {
// 用时
long testTime = Helper.differMinute(rtp.getModifyTime().toString(), rtp.getCreateTime().toString());
if (testTime == 0) {
testTime = 1;
}
map.put("testTime", testTime);
map.put("validity", rtp.getValidity());
map.put("createTime", rtp.getCreateTime());
map.put("type1", rtp.getType1());
map.put("type2", rtp.getType2());
map.put("type3", rtp.getType3());
map.put("type4", rtp.getType4());
map.put("type5", rtp.getType5());
map.put("flag", rtp.getFlag());
map.put("tpid", rtp.getId());
}
} else {
map.put("isNull", 1);
}
chooseList.add(map);
modelMap.addAttribute("chooseList", chooseList);
}
}
return createModelAndView("analystsc/lzteamversion_test", modelMap);
jsp
<div class="for_page">
<div class="aboutBtn clearFixed">
<div class="pageBtn testRecordBtn searchAllBtns">
<c:if test="${paging.pageID > 1 }">
<a href="${paging.pagingUrl }&pageID=${paging.pageID-1}" class='pageNum lastPage'><i>上一页</i></a>
</c:if>
<c:choose>
<c:when test="${paging.pageID==paging.pageCount }">
<c:if test="${paging.pageID>3 && paging.pageCount-5>0 }">...</c:if>
<c:if test="${paging.pageID>4 }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID-4}">${paging.pageID-4 }</a>
</c:if>
<c:if test="${paging.pageID>3 }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID-3}">${paging.pageID-3 }</a>
</c:if>
</c:when>
<c:when test="${paging.pageID==paging.pageCount-1 }">
<c:if test="${paging.pageID>3 && paging.pageCount-5>0 }">...</c:if>
<c:if test="${paging.pageID>3 }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID-3}">${paging.pageID-3 }</a>
</c:if>
</c:when>
<c:otherwise>
<c:if test="${paging.pageID>3 && paging.pageCount-5>0 }">...</c:if>
</c:otherwise>
</c:choose>
<c:if test="${paging.pageID>2 }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID-2}">${paging.pageID-2 }</a>
</c:if>
<c:if test="${paging.pageID>1 }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID-1}">${paging.pageID-1 }</a>
</c:if>
<a class='pageNum clickPage onPage' href="${paging.pagingUrl }&pageID=${paging.pageID}" >${paging.pageID }</a>
<c:if test="${paging.pageID<paging.pageCount }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID+1}">${paging.pageID+1 }</a>
</c:if>
<c:if test="${paging.pageID<paging.pageCount-1 }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID+2}">${paging.pageID+2 }</a>
</c:if>
<c:choose>
<c:when test="${paging.pageID==1 }">
<c:if test="${paging.pageID<paging.pageCount-2 }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID+3}">${paging.pageID+3 }</a>
</c:if>
<c:if test="${paging.pageID<paging.pageCount-3 }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID+4}">${paging.pageID+4 }</a>
</c:if>
<c:if test="${paging.pageID<paging.pageCount-4 }">...</c:if>
</c:when>
<c:when test="${paging.pageID==2 }">
<c:if test="${paging.pageID<paging.pageCount-2 }">
<a class='pageNum clickPage' href="${paging.pagingUrl }&pageID=${paging.pageID+3}">${paging.pageID+3 }</a>
</c:if>
<c:if test="${paging.pageID<paging.pageCount-3 }">...</c:if>
</c:when>
<c:otherwise>
<c:if test="${paging.pageID<paging.pageCount-2 }">...</c:if>
</c:otherwise>
</c:choose>
<c:if test="${paging.pageID < paging.pageCount }">
<a href="${paging.pagingUrl }&pageID=${paging.pageID+1}" class='pageNum nextPage'><i>下一页</i></a>
</c:if>
</div>
<div class="searchBtn testRecordBtn">
<span class="searchTestR searchAll onSearch">查看所有</span>
<span class="searchTestR searchChoosed">查看选中</span>
</div>
</div>
</div>
js脚本
$(document).ready(function(){
function showLastPage(){ //此方法用于判断‘上一页’按钮是否禁用
if($('.pageBtn .clickPage:first').hasClass('onPage')){
$('.pageBtn .lastPage').addClass('disAbled');
}else{
$('.pageBtn .lastPage').removeClass('disAbled');
}
};
function showSearchLastPage(){ //此方法用于判断‘上一页’按钮是否禁用, 查看选中
if($('.pageBtn .searchclickPage:first').hasClass('onPage')){
$('.pageBtn .searchlastPage').addClass('disAbled');
}else{
$('.pageBtn .searchlastPage').removeClass('disAbled');
}
};
showLastPage();
showSearchLastPage();
$('.pageBtn .clickPage').on('click',function(){ //按钮样式的变化
$(this).addClass('onPage').siblings('.clickPage').removeClass('onPage');
showLastPage();
$('.memberTRecord .Record_ul').eq($(this).index()).show().siblings('.Record_ul').hide(); // 显示哪一页的数据
});
$('.pageBtn .searchclickPage').on('click',function(){ //按钮样式的变化,查看选中
$(this).addClass('onPage').siblings('.searchclickPage').removeClass('onPage');
showSearchLastPage();
});
$('.pageBtn .lastPage').click(function(event) { //点击‘上一页’按钮
var onBtnIndex=$('.pageBtn .clickPage[class*="onPage"]').index();
$('.pageBtn .clickPage').eq(onBtnIndex-1).addClass('onPage').siblings('.clickPage').removeClass('onPage');
showLastPage();
});
$('.pageBtn .searchlastPage').click(function(event) { //点击‘上一页’按钮 查看选中
var onBtnIndex=$('.pageBtn .searchclickPage[class*="onPage"]').index();
$('.pageBtn .searchclickPage').eq(onBtnIndex-1).addClass('onPage').siblings('.searchclickPage').removeClass('onPage');
showSearchLastPage();
});
$('.pageBtn .nextPage').click(function(event) { //点击‘下一页’按钮
var onBtnIndex=$('.pageBtn .clickPage[class*="onPage"]').index();
$('.pageBtn .clickPage').eq(onBtnIndex+1).addClass('onPage').siblings('.clickPage').removeClass('onPage');
});
$('.pageBtn .searchnextPage').click(function(event) { //点击‘下一页’按钮 ,查看选中
var onBtnIndex=$('.pageBtn .searchclickPage[class*="onPage"]').index();
$('.pageBtn .searchclickPage').eq(onBtnIndex+1).addClass('onPage').siblings('.searchclickPage').removeClass('onPage');
});
$('.searchBtn .searchTestR').on('click',function(){ //按钮样式的变化
$(this).addClass('onSearch').siblings('.searchTestR').removeClass('onSearch');
});
$('.searchBtn .searchAll').on('click',function(){ //按钮样式的变化
$('.Record_ul li').show();
$('.searchChoosedBtns').hide();
$('.searchAllBtns').show();
});
$('.searchBtn .searchChoosed').on('click',function(){ //按钮样式的变化
$('.Record_ul li input[checked!="true"]').parent('li').hide();
$('.Record_ul li input:checked').parent('li').show();
$('.searchAllBtns').hide();
$('.searchChoosedBtns').show();
});
});
//当前页数ID
private Integer pageID;
//一页的列表项的数目
private Integer onePageItemCount;
//列表项总数
private Integer itemCount;
//一共页数
private Integer pageCount;
//分页查询开始ID
private Integer beginID;
//当前分页网页的链接
private String pagingUrl;
/**
* 初始化分页Model
* @param pageID 当前页数ID
* @param onePageItemCount 一页的列表项的数目
* @param itemCount 列表项总数
*/
public PagingModel(
Integer pageID,
Integer onePageItemCount,
Integer itemCount) {
//获取当前页数ID
pageID = Helper.toInt(pageID);
if(pageID<=0) {
pageID = 1;
}
this.pageID = pageID;
//一页显示多少数量
this.onePageItemCount = Helper.toInt(onePageItemCount);
if(this.onePageItemCount<=0) {
this.onePageItemCount = 1;
}
//列表项总数
this.itemCount = Helper.toInt(itemCount);
//总页数 = 总数量/一页显示多少数量
this.pageCount = this.itemCount/this.onePageItemCount;
if(this.itemCount%this.onePageItemCount > 0) {
this.pageCount += 1;
}
//开始数 = (当前页-1)* 一页显示数量
this.beginID = (this.pageID-1)*this.onePageItemCount;
}
/**
* <p>开始分页</p>
* <p>1.保存分页MODEL</p>
* <p>2.保存当前地址:用于分页链接</p>
* @param modelMap
* @param request
* @author ziry
* @return
* <p>0:正确开始</p>
* <p>-1:异常</p>
*/
public int openPaging(ModelMap modelMap, HttpServletRequest request) {
try {
//获取当前网址
pagingUrl = request.getRequestURL().toString();
//获取访问URL所带参数
String par = request.getQueryString();
//如果有参数则合并
if(par != null){
pagingUrl += "?" + request.getQueryString();
} else {
pagingUrl += "?paging=true";
}
pagingUrl = pagingUrl.replaceAll("&pageID=\\d", "");
//保存分页
modelMap.addAttribute("paging", this);
return 0;
} catch(Exception e){
e.printStackTrace();
}
return -1;
}
public Integer getPageID() {
return pageID;
}
public void setPageID(Integer pageID) {
this.pageID = pageID;
}
public Integer getOnePageItemCount() {
return onePageItemCount;
}
public void setOnePageItemCount(Integer onePageItemCount) {
this.onePageItemCount = onePageItemCount;
}
public Integer getItemCount() {
return itemCount;
}
public void setItemCount(Integer itemCount) {
this.itemCount = itemCount;
}
public Integer getPageCount() {
return pageCount;
}
public void setPageCount(Integer pageCount) {
this.pageCount = pageCount;
}
public Integer getBeginID() {
return beginID;
}
public void setBeginID(Integer beginID) {
this.beginID = beginID;
}
public String getPagingUrl() {
return pagingUrl;
}
public void setPagingUrl(String pagingUrl) {
this.pagingUrl = pagingUrl;
}