Search in sources :

Example 6 with PageHelper

use of com.github.pagehelper.PageHelper in project new-cloud by xie-summer.

the class MybatisConfigurer method sqlSessionFactoryBean.

@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setTypeAliasesPackage(MybatisConstant.MODEL_PACKAGE);
    // 分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);
    /**
     *abel533通用mapper
     */
    // MapperInterceptor mapperInterceptor = new MapperInterceptor();
    // Properties props = new Properties();
    // /**--主键自增回写方法,默认值MYSQL,详细说明请看文档 -->*/
    // props.setProperty("IDENTITY","MYSQL");
    // /**<!--通用Mapper接口,多个通用接口用逗号隔开 -->*/
    // props.setProperty("mappers", "com.github.abel533.mapper.IMapper");
    // mapperInterceptor.setProperties(props);
    // 添加插件
    bean.setPlugins(new Interceptor[] { pageHelper });
    // bean.setPlugins(new Interceptor[]{mapperInterceptor});
    // 添加XML目录
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
    return bean.getObject();
}
Also used : PageHelper(com.github.pagehelper.PageHelper) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Properties(java.util.Properties) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with PageHelper

use of com.github.pagehelper.PageHelper in project new-cloud by xie-summer.

the class MybatisConfigurer method sqlSessionFactoryBean.

@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setTypeAliasesPackage(MybatisConstant.MODEL_PACKAGE);
    // 分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);
    bean.setPlugins(new Interceptor[] { pageHelper });
    // 添加XML目录
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    bean.setMapperLocations(resolver.getResources("classpath:mapper/**.xml"));
    return bean.getObject();
}
Also used : PageHelper(com.github.pagehelper.PageHelper) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Properties(java.util.Properties) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 8 with PageHelper

use of com.github.pagehelper.PageHelper in project new-cloud by xie-summer.

the class MybatisConfigurer method sqlSessionFactoryBean.

@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setTypeAliasesPackage(MybatisConstant.MODEL_PACKAGE);
    // 分页插件
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);
    bean.setPlugins(new Interceptor[] { pageHelper });
    // 添加XML目录
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    bean.setMapperLocations(resolver.getResources("classpath:mapper/**.xml"));
    return bean.getObject();
}
Also used : PageHelper(com.github.pagehelper.PageHelper) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Properties(java.util.Properties) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 9 with PageHelper

use of com.github.pagehelper.PageHelper in project spring-cloud-framework by zhuwj921.

the class PageHelperConfiguration method pageHelper.

@Bean
public PageHelper pageHelper() {
    logger.info("PageHelperConfiguration.pageHelper()");
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("offsetAsPageNum", "true");
    properties.setProperty("rowBoundsWithCount", "true");
    properties.setProperty("reasonable", "true");
    pageHelper.setProperties(properties);
    return pageHelper;
}
Also used : PageHelper(com.github.pagehelper.PageHelper) Properties(java.util.Properties) Bean(org.springframework.context.annotation.Bean)

Example 10 with PageHelper

use of com.github.pagehelper.PageHelper in project sinsim by WilsonHu.

the class MybatisConfig method sqlSessionFactoryBean.

@Bean
public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);
    factory.setTypeAliasesPackage(MODEL_PACKAGE + "/*");
    // 配置分页插件,详情请查阅官方文档
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    // 分页尺寸为0时查询所有纪录不再执行分页
    properties.setProperty("pageSizeZero", "true");
    // 页码<=0 查询第一页,页码>=总页数查询最后一页
    properties.setProperty("reasonable", "true");
    // 支持通过 Mapper 接口参数来传递分页参数
    properties.setProperty("supportMethodsArguments", "true");
    pageHelper.setProperties(properties);
    // 添加插件
    factory.setPlugins(new Interceptor[] { pageHelper });
    // 添加XML目录
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
    // /通过Java配置的方式是通过setConfiguration/setConfigLocation,而setConfigurationProperties只是
    // 配置文件中的一个property。所以mybatis的配置,要不通过XML的location方式,要不就是setConfiguration后
    // 加上property的方式Properties
    // mybatisProperties = new Properties();
    // mybatisProperties.setProperty("mapUnderscoreToCamelCase", "true");
    // factory.setConfigurationProperties(mybatisProperties);
    factory.setConfigLocation(resolver.getResource("classpath:mybatis-config.xml"));
    return factory.getObject();
}
Also used : PageHelper(com.github.pagehelper.PageHelper) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Properties(java.util.Properties) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

PageHelper (com.github.pagehelper.PageHelper)12 Properties (java.util.Properties)12 Bean (org.springframework.context.annotation.Bean)12 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)11 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)11 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)9 ConfigurationProperties (org.springframework.boot.context.properties.ConfigurationProperties)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)1