后端接口: springboot+mybatis+pageHelper
@RequestMapping(value = "/getUserinfo") @ResponseBody public List<AppUser> getSomePerson(@RequestParam(value = "pageNum",defaultValue="1") int pageNum,HttpServletRequest request ){ //pageNum:表示第几页 pageSize:表示一页展示的数据 PageHelper.startPage(pageNum,5); List<AppUser> list=appUserServices.getAllUserInfo(); //将查询到的数据封装到PageInfo对象 PageInfo<AppUser> pageInfo=new PageInfo(list,5); //分割数据成功 for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } request.setAttribute("userinfopage",pageInfo); return list; }
前端页面”:bootstrap+jqery
<script> $(function (){ //请求信息 $.ajax({url:"/plat/getUserinfo",success:function(data){ var str = ""; console.log(data[0].appUserGroup.name); console.log(data[0].id); for (i in data) { str+=" <tr>\n" + " <td>"+(1+parseInt(i))+"</td>\n" + " <td>"+data[i].userid+"</td>\n" + " <td>"+(data[i].password==""?"无":"******")+"</td>\n" + " <td>"+data[i].name+"</td>\n" + " <td>"+data[i].appUserGroup.name+"</td>\n" + " <td>"+(parseInt(data[i].status)==0?"有效":"无效")+"</td>\n" + " <td><a href=\"#\">更换用户角色</a></td>\n" + " <td><a href=\"#\">修改</a></td>\n" + " <td><a href=\"#\">删除</a></td>\n" + " </tr>"; } $("#table_userinfo").append(str); console.log(data); }}); }) </script> <body> <div> <!-- 表格 --> <table class="table table-bordered" > <tr> <th>序号</th> <th>账号</th> <th>密码</th> <th>姓名</th> <th>部门</th> <th>状态</th> <th>用户角色</th> <th>修改</th> <th>删除</th> </tr> <tbody id="table_userinfo" class="table table-bordered"> </tbody> </table>
</body>