zoukankan      html  css  js  c++  java
  • SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

    SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

    **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了。全部自动实现。
    话不多说,直接上代码:

    第一步pom文件配置添加jar:###

    <!-- mybatis的分页插件 -->
    <dependency>
       <groupId>com.github.pagehelper</groupId>
       <artifactId>pagehelper</artifactId>
       <version>4.1.6</version>
    </dependency>				    
    

    第二步配置application.properties文件或者 application.yml 文件:###

    注意你是配置的什么数据进行分页操作 pagehelper.helperDialect=postgresql 我这里是postgresql数据库
    支持Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库

    application.properties:###

    #pagehelper分页插件配置
    pagehelper.helperDialect=mysql
    pagehelper.reasonable=true
    pagehelper.supportMethodsArguments=true
    pagehelper.params=count=countSql
    

    application.yml

    pagehelper:
      helperDialect: mysql
      reasonable: true
      supportMethodsArguments: true
      params: count=countSql
    

    第三步配置运行类 Application 添加pagehelp插件,在main方法之后被加载###

    @SpringBootApplication
    //将项目中对应的mapper类的路径加进来就可以了
    @MapperScan({"org.baihuida.hints.dao"})
    public class CodeHintsApplication {
    
    	public static void main(String[] args) {
    		SpringApplication.run(CodeHintsApplication.class, args);
    	}
    	
    	//配置mybatis的分页插件pageHelper
        @Bean
        public PageHelper pageHelper(){
            PageHelper pageHelper = new PageHelper();
            Properties properties = new Properties();
            properties.setProperty("offsetAsPageNum","true");
            properties.setProperty("rowBoundsWithCount","true");
            properties.setProperty("reasonable","true");
            properties.setProperty("dialect","mysql");    //配置mysql数据库的方言
            pageHelper.setProperties(properties);
            return pageHelper;
        }
        
    }
    

    第四步配置controller层:

    @RequestMapping("queryKeywords")
    	public PageInfo<Keywords> queryKeywords(@RequestParam(defaultValue="1") int pageNum, 
    			   @RequestParam(defaultValue="3") int pageSize) {
    		
    		PageInfo<Keywords> pageInfo = keywordsService.getLogInfoPage(pageNum,pageSize);
    		return pageInfo;
    	}
    

    第五步配置service层:

    @Override
    	public PageInfo<Keywords> getLogInfoPage(int pageNum, int pageSize) {
    		PageHelper.startPage(pageNum,pageSize);
            List<Keywords> list= keywordsMapper.listKeywords();
            PageInfo<Keywords> pageInfo = new PageInfo<Keywords>(list);
    		
    		return pageInfo;
    	}
    

    第六步配置 service

    public PageInfo<Keywords> getLogInfoPage(int pageNum, int pageSize);

    实现类

    @Override
    public PageInfo<Keywords> getLogInfoPage(int pageNum, int pageSize) {
    	PageHelper.startPage(pageNum,pageSize);
        List<Keywords> list= keywordsMapper.listKeywords();
        PageInfo<Keywords> pageInfo = new PageInfo<Keywords>(list);
    	
    	return pageInfo;
    }
    

    第七步Dao层:

    List<Keywords> listKeywords();
    
    

    第八步xml层:

    <select id="listKeywords" resultType="org.baihuida.hints.entity.Keywords">
    
        select keyword from keywords
    
      </select>
    
    
  • 相关阅读:
    hdu 2147博弈找规律
    hdu 1851 巴什博弈
    hdu 1729 sg博弈
    hdu 2516博弈找规律
    (转载)博弈之SG函数
    poj 2234基础Nim博弈||sg博弈
    hdu 1730 sg博弈||nim博弈
    hdu 1847 博弈找规律
    n hdu 1760 [SG博弈]二维状态
    hdu 1849 nim博弈
  • 原文地址:https://www.cnblogs.com/jixu8/p/9410852.html
Copyright © 2011-2022 走看看