springboot分页操作

1、后端首先在config下添加组件

————————————————————————————————————————————————————————————
//分页插件
@Configuration
public class myBatisConfig {
@Bean
public MybatisPlusInterceptor paginationInterceptor(){
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
PaginationInnerInterceptor paginationInnerInterceptor =new PaginationInnerInterceptor();
paginationInnerInterceptor.setOverflow(true); //设置ture跳转到首页
paginationInnerInterceptor.setMaxLimit(500L);

mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
return mybatisPlusInterceptor;
}
}
————————————————————————————————————————————————————————————

2、后端然后在service文件夹下创建UserService接口,然后再在service/implments文件夹下创建UserService接口的实现类

————————————————————————————————————————————————————————————
public interface UserService extends IService {

}
————————————————————————————————————————————————————————————
@Service
public class UserServiceImp extends ServiceImpl<UserMapper,User> implements UserService {
}
@Autowired
UserService userService;

@GetMapping(“/editable_table”)
public String editable_table(@RequestParam(value = “p”, defaultValue = “1”) Integer p, Model model) {
/* List list = userService.list();
model.addAttribute(“users”, list);*/
//分页查询数据
Page userPage = new Page<>(p, 5);
//分页查询的结果
Page page = userService.page(userPage, null);
long current = page.getCurrent();
long pages = page.getPages();
long total = page.getTotal();
List records = page.getRecords();
model.addAttribute(“page”,page);
return “table/editable_table”;
}
————————————————————————————————————————————————————————————
3、前端代码如下

<tbody>
      <tr class="" th:each="user:${page.records}">
	  <td>[[${user.id}]]</td>
	  <td th:text="${user.name}">3455</td>
	  <td class="center" th:text="${user.age}">Lorem ipsume</td>
	  <td>[[${user.emil}]]</td>
	  <td><a class="delete" href="javascript:;">Delete</a></td>
	   </tr>
</tbody>


<div class="row">
       <div class="col-lg-6">
       <div class="dataTables_info" id="editable-sample_info">当前第[[${page.current}]]页 总计[[${page.pages}]]页 共[[${page.total}]]条记录
       </div>
       </div>
       <div class="col-lg-6">
       <div class="dataTables_paginate paging_bootstrap pagination">
       <ul>
       <li class="prev disabled"><a href="#">前一页</a></li>
       <li th:class="${num==page.current?'active':''}" th:each="num:${#numbers.sequence(1,page.pages)}">
       <a th:href="@{/editable_table(p=${num})}">[[${num}]]</a>
       <li class="next"><a href="#">下一页</a></li>
       </ul>
       </div>
       </div>
</div>

但是上述分页操作在后端开发中是不经常使用的,我们经常使用js完成分页操作,后端只需要通过接口传输数据库的数据给前端页面显示即可

4、如下
————————————————————————————————————————————————————————————
@Autowired
UserService userService;

@GetMapping("/editable_table")
public String editable_table(Model model) {
    List<User> list = userService.list();
    model.addAttribute("users", list);
    return "table/editable_table";
}

————————————————————————————————————————————————————————————

 <tbody>
       <tr class="" th:each="user:${users}">
	       <td>[[${user.id}]]</td>
	       <td th:text="${user.name}">3455</td>
	       <td class="center" th:text="${user.age}">Lorem ipsume</td>
	       <td>[[${user.emil}]]</td>
	       <td><a class="delete" href="javascript:;">Delete</a></td>
       </tr>
 </tbody>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Q渡劫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值