zoukankan      html  css  js  c++  java
  • pagehelper 分页

    分页jar包:

    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.1.1</version>
    </dependency>

    配置:

    import java.util.Properties;

    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;

    import com.github.pagehelper.PageInterceptor;

    @Configuration
    public class PageHelperConfig {

    @Value("${pagehelper.helperDialect}")
    private String helperDialect;


    @Bean
    public PageInterceptor pageInterceptor() {
    PageInterceptor pageInterceptor = new PageInterceptor();
    Properties properties = new Properties();
    properties.setProperty("helperDialect", helperDialect);
    pageInterceptor.setProperties(properties);
    return pageInterceptor;
    }
    }

    package test.test.config;
    
    import javax.sql.DataSource;
    
    import org.apache.ibatis.plugin.Interceptor;
    import org.apache.ibatis.session.SqlSessionFactory;
    import org.mybatis.spring.SqlSessionFactoryBean;
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.core.env.Environment;
    import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
    import org.springframework.jdbc.datasource.DataSourceTransactionManager;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    
    import com.github.pagehelper.PageInterceptor;
    
    @Configuration
    @MapperScan("com.xx.dao")
    @EnableTransactionManagement
    public class DataSourceConfig {
    
        @Autowired
        private Environment env;
    
        @Autowired
        private PageInterceptor PageInterceptor;
    
        @Bean
        public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
            SqlSessionFactoryBean fb = new SqlSessionFactoryBean();
            fb.setDataSource(dataSource);
            // 该配置非常重要,如果不将PageInterceptor 设置到SqlSessionFfactory中,导致分页失效
            fb.setPlugins(new Interceptor[] {PageInterceptor});
            fb.setTypeAliasesPackage(env.getProperty("mybaertis.type-aliases-package"));
            fb.setMapperLocations(new PathMatchingResourcePatternResolver()
                    .getResources(env.getProperty("mybatis.mapper.locations")));
            return fb.getObject();
        }
    
        @Bean
        public DataSourceTransactionManager transactionManager(DataSource dataSource) {
            DataSourceTransactionManager dataSourceTransactionManager =
                    new DataSourceTransactionManager();
            dataSourceTransactionManager.setDataSource(dataSource);
            return dataSourceTransactionManager;
        }
    
    
    }

    配置文件配置

    pagehelper.helperDialect = oracle
    pagehelper.reasonable = true
    pagehelper.supportMethodsArguments = true
    pagehelper.params = count=countSql
    pagehelper.returnPageInfo = check

    使用:
    @RequestParam(name="pageNum",required =false,defaultValue="1") int pageNum,
    @RequestParam(name="pageSize",required =false,defaultValue="1") int pageSize

    PageHelper.startPage( pageNum,pageSize);

  • 相关阅读:
    Android Overlay学习
    为WinForm combox控件增加自动完成功能
    职业理想
    How to become a hacerk.黑客
    .net程序员常用网站
    面向对象设计原则
    net开源cms系统
    如何:禁用 Windows 窗体 DataGridView 控件的按钮列中的按钮(摘录)
    计算机编码(百度百科)
    .net winform 从资源文件中引用图片资源
  • 原文地址:https://www.cnblogs.com/yrjns/p/10838408.html
Copyright © 2011-2022 走看看