|
@@ -0,0 +1,36 @@
|
|
|
+package com.rtrh.projects.baseConfig;
|
|
|
+
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
+import org.mybatis.spring.SqlSessionFactoryBean;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
|
+import javax.sql.DataSource;
|
|
|
+import java.util.Properties;
|
|
|
+
|
|
|
+@Configuration
|
|
|
+public class MyBatisConfig {
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public PageHelper pageHelper() {
|
|
|
+ PageHelper pageHelper = new PageHelper();
|
|
|
+ Properties properties = new Properties();
|
|
|
+ properties.setProperty("dialect", "mysql"); // 数据库方言
|
|
|
+ properties.setProperty("reasonable", "true"); // 启用合理化分页
|
|
|
+ properties.setProperty("offsetAsPageNum", "true");
|
|
|
+ properties.setProperty("rowBoundsWithCount", "true");
|
|
|
+ pageHelper.setProperties(properties);
|
|
|
+ return pageHelper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
|
|
|
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
|
|
|
+ factoryBean.setDataSource(dataSource);
|
|
|
+ factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml"));
|
|
|
+ // 添加分页插件
|
|
|
+ factoryBean.setPlugins(new org.apache.ibatis.plugin.Interceptor[]{pageHelper()});
|
|
|
+ return factoryBean.getObject();
|
|
|
+ }
|
|
|
+}
|