Skip to content

Commit

Permalink
update for 分页
Browse files Browse the repository at this point in the history
  • Loading branch information
leedar360 committed Nov 5, 2015
1 parent b50f8b4 commit ecf263c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public String toCreate() {
@RequestMapping(value="/list", method=RequestMethod.GET)
public String list(@RequestParam(value="page",defaultValue="1") int page,
@RequestParam(value="size",defaultValue="10") int size,Model model) {
size = ConstantUtil.PAGE_SIZE;
int totalNum = service.getTotalNum();
int totalPage = totalNum < size ? 1 : (int)Math.ceil(1.0 * totalNum / size);
model.addAttribute("totalPage", totalPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.zmsport.iyuesai.service.UserService;
import com.zmsport.iyuesai.service.UserTeamLikeService;
import com.zmsport.iyuesai.service.UserTeamService;
import com.zmsport.iyuesai.util.ConstantUtil;
import com.zmsport.iyuesai.util.FileUtil;

/**
Expand Down Expand Up @@ -72,6 +73,7 @@ public class UserController {
@RequestMapping(value="/list", method=RequestMethod.GET)
public String list(@RequestParam(value="page",defaultValue="1") int page,
@RequestParam(value="size",defaultValue="10") int size,Model model) {
size = ConstantUtil.PAGE_SIZE;
int totalNum = service.getTotalCount();
int totalPage = totalNum < size ? 1 : (int)Math.ceil(1.0 * totalNum / size);
model.addAttribute("totalPage", totalPage);
Expand Down
20 changes: 20 additions & 0 deletions src/main/webapp/admin/pages/teamList.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<!--
$(function(){
PageUtil.init();
PageUtil.initPage();
});
var PageUtil = {
init :function(){
Expand Down Expand Up @@ -55,6 +56,24 @@
}
window.location.href = '<c:url value="/admin/team/list?page=" />' + page;
}
},
initPage :function() {
var currentPage = <c:out value="${currentPage}" />;
var totalPage = <c:out value="${totalPage}" />;
var section = currentPage <= 10 ? 1 : Math.ceil(currentPage / 10);
var minPage = (section - 1) * 10 + 1;
var lastPage = (minPage + 9) < totalPage ? (minPage + 9) : totalPage;
var txt;
$('div.page a').each(function(){
txt = $(this).text();
if(txt.indexOf("") < 0) {
if(txt*1 >= minPage && txt <= lastPage) {
$(this).show();
}else {
$(this).hide();
}
}
});
}
};
//-->
Expand Down Expand Up @@ -114,6 +133,7 @@
</c:forEach>
</table>
<div class="page">
<a href="<c:url value="/admin/team/list?page=1" />">首页</a>
<c:if test="${currentPage > 1}">
<a href="<c:url value="/admin/team/list?page=" />${currentPage-1}">上一页</a>
</c:if>
Expand Down
22 changes: 22 additions & 0 deletions src/main/webapp/admin/pages/userList.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<script type="text/javascript" src="<c:url value="/admin/js/jquery.min.js" />"></script>
<script type="text/javascript">
<!--
$(function(){
PageUtil.initPage();
});
var PageUtil = {
del : function(id) {
if(confirm("如果删除的是球队创建者,则球队将自动删除,是否继续?")) {
Expand All @@ -22,6 +25,24 @@
}
window.location.href = '<c:url value="/admin/user/list?page=" />' + page;
}
},
initPage :function() {
var currentPage = <c:out value="${currentPage}" />;
var totalPage = <c:out value="${totalPage}" />;
var section = currentPage <= 10 ? 1 : Math.ceil(currentPage / 10);
var minPage = (section - 1) * 10 + 1;
var lastPage = (minPage + 9) < totalPage ? (minPage + 9) : totalPage;
var txt;
$('div.page a').each(function(){
txt = $(this).text();
if(txt.indexOf("") < 0) {
if(txt*1 >= minPage && txt <= lastPage) {
$(this).show();
}else {
$(this).hide();
}
}
});
}
};
//-->
Expand Down Expand Up @@ -78,6 +99,7 @@
</c:forEach>
</table>
<div class="page">
<a href="<c:url value="/admin/user/list?page=1" />">首页</a>
<c:if test="${currentPage > 1}">
<a href="<c:url value="/admin/user/list?page=" />${currentPage-1}">上一页</a>
</c:if>
Expand Down

0 comments on commit ecf263c

Please sign in to comment.