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();
}
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();
}
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();
}
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;
}
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();
}
Aggregations