码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Springboot整合分页插件pagehelper


    首先需要有一定的springboot+mybatis的基础,才能使用顺畅


    项目结构如下



    引入依赖,springboot版本选的是2.7.16版本,jdk选的17,


    
    
        com.github.pagehelper
        pagehelper-spring-boot-starter
        1.4.6
    

     mapper层


     

    @Mapper
    public interface InsectDao {
    
       List selectAll();
    
    }
    

     service接口层


    public interface InsectService {
    
        List selectAll();
    
    }

    service实现类


    @Service
    public class InsectServiceImpl implements InsectService {
        @Resource
        private InsectDao insectDao;
    
    
        @Override
        public List selectAll() {
            return insectDao.selectAll();
        }
    }
    

     


     controller层


    @RestController
    public class InsectController {
        /**
         * 服务对象
         */
        @Resource
        private InsectService insectService;
    
       @GetMapping("/insect")//分页ok了
        public PageInfo selectAll(){
    
           System.out.println("进来了首页");
    
           PageHelper.startPage(1,2);
    
           List list =insectService.selectAll();
    
           PageInfo pageInfo = new PageInfo<>(list);
    
           pageInfo.setList(list);
    
           System.out.println("看看分页"+list);
    
           System.out.println("看看分页1"+pageInfo);
    
           return pageInfo;
       }
    
    
    }
    

     mapper层xml,对应mapper层的接口方法


    
    
    
    
        
            
            
            
            
            
            
        
    
        
    
    
    
    

     application核心配置文件如下


    server:
      port: 8045
    
    spring:
      datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/t155
        username: root
        password: root
    
      thymeleaf:
        suffix: .html
        prefix: classpath:/templates/
    
    mybatis:
      mapper-locations: classpath:mapper/*.xml
    

     接下来就可以进行测试了


    测试效果如下,输入地址进行测试,参数可以自行去了解一下,希望可以帮助各位小伙伴



     到这里就已经ok了!!

  • 相关阅读:
    前端基础之JavaScript
    JavaEE进阶 - SpringBoot 统⼀功能处理 - 细节狂魔
    Nacos单机配置集群配置
    WorkPlus移动数字化平台高定制化服务,贴身满足企业的个性化需求
    云服务器租用4核16G配置价格表,阿里云和腾讯云费用价格对比
    非常小的一个东西,Spring依赖注入Bean类型的8种情况
    数据在内存中的存储——练习3
    始祖双碳新闻 | 2022年8月18日碳中和行业早知道
    钡铼R40边缘计算网关与华为云合作,促进物联网传感器数据共享与应用
    arthas修改日志级别
  • 原文地址:https://blog.csdn.net/weixin_69218754/article/details/133206582
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号