File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
java/com/linkinstars/springBootTemplate/controller Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 11package com .linkinstars .springBootTemplate .controller ;
22
33import com .github .pagehelper .PageHelper ;
4+ import com .github .pagehelper .PageInfo ;
45import com .linkinstars .springBootTemplate .bean .UserEntity ;
56import com .linkinstars .springBootTemplate .service .IUserService ;
67import org .springframework .beans .factory .annotation .Autowired ;
@@ -23,12 +24,15 @@ public class UserController {
2324 @ RequestMapping ("/test" )
2425 public String test (HttpServletRequest request , @ RequestParam (required = false ) Integer pageNum ){
2526 int pageSize = 3 ;
26- if (pageNum == null ) {
27+ if (pageNum == null || pageNum < 1 ) {
2728 pageNum = 1 ;
2829 }
2930 PageHelper .startPage (pageNum , pageSize );
3031 List <UserEntity > userList = userService .listUser ();
32+ PageInfo pageInfo = new PageInfo (userList );
3133 request .setAttribute ("userList" , userList );
34+ request .setAttribute ("pageNum" , pageNum );
35+ request .setAttribute ("pageSum" , pageInfo .getPages ());
3236 return "index" ;
3337 }
3438}
Original file line number Diff line number Diff line change 1+ function jumpPage ( pageNum , pageSum ) {
2+ pageNum = parseInt ( pageNum ) ;
3+ pageSum = parseInt ( pageSum ) ;
4+ if ( pageNum < 1 || pageNum > pageSum ) {
5+ return "当前选择的页码没有数据" ;
6+ }
7+ return true ;
8+ }
Original file line number Diff line number Diff line change 1313 < td th:text ="${user.val} "> 2</ td >
1414 </ tr >
1515</ table >
16+ < input type ="button " value ="上一页 " th:onclick ="'gotoPage('+${pageNum-1}+', '+${pageSum}+')' " th:if ="${pageNum ne 1} "/>
17+ < span th:text ="${pageNum} "> </ span > / < span th:text ="${pageSum} "> </ span >
18+ < input type ="button " value ="下一页 " th:onclick ="'gotoPage('+${pageNum+1}+', '+${pageSum}+')' " th:if ="${pageNum ne pageSum} "/>
19+ < br />
20+
21+ < form th:action ="@{/test} " method ="post ">
22+ < input type ="number " th:value ="${pageNum} " name ="pageNum "/>
23+ < input type ="submit " value ="跳转 "/>
24+ </ form >
25+
26+ < script type ="application/javascript " src ="../static/js/public.js " th:src ="@{/js/public.js} "/>
27+ < script type ="application/javascript " >
28+ function gotoPage ( pageNum , pageSum ) {
29+ var result = jumpPage ( pageNum , pageSum ) ;
30+ if ( result == true ) {
31+ window . location . href = "?pageNum=" + pageNum ;
32+ } else {
33+ alert ( result ) ;
34+ }
35+ }
36+ </ script >
1637</ body >
1738</ html>
You can’t perform that action at this time.
0 commit comments