Search in sources :

Example 11 with PageHelper

use of com.github.pagehelper.PageHelper in project spring-boot-api-seed-project by selfassu.

the class MybatisConfigurer method sqlSessionFactoryBean.

@Bean(name = "sqlSessionFactoryBean")
public SqlSessionFactory sqlSessionFactoryBean(@Qualifier("dataSource") DataSource dataSource) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);
    sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper/*Mapper.xml"));
    // 给 model 设置别名
    sqlSessionFactoryBean.setTypeAliasesPackage(ProjectConstants.BASE_TARGET_PACKAGE + ProjectConstants.MODEL_PACKAGE_SUFFIX);
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("pageSizeZero", "true");
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    pageHelper.setProperties(properties);
    // 设置分页插件 TODO 这里有问题
    sqlSessionFactoryBean.setPlugins(new Interceptor[] { (Interceptor) pageHelper });
    return sqlSessionFactoryBean.getObject();
}
Also used : PageHelper(com.github.pagehelper.PageHelper) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Properties(java.util.Properties) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 12 with PageHelper

use of com.github.pagehelper.PageHelper in project CBEC-B2B by A-Cubic.

the class DataSourceConfig method sqlSessionFactoryBean.

@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    // mybatis分页
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "false");
    // props.setProperty("returnPageInfo", "check");
    // props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props);
    // 添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[] { pageHelper });
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
Also used : PageHelper(com.github.pagehelper.PageHelper) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Properties(java.util.Properties) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) 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