content: package com.transaction.config;
  
  import com.alibaba.druid.pool.DruidDataSource;
  import com.alibaba.druid.support.http.StatViewServlet;
  import com.alibaba.druid.support.http.WebStatFilter;
  import com.github.pagehelper.PageHelper;
  import lombok.extern.slf4j.Slf4j;
  import org.apache.ibatis.plugin.Interceptor;
  import org.apache.ibatis.session.SqlSessionFactory;
  import org.mybatis.spring.SqlSessionFactoryBean;
  import org.mybatis.spring.SqlSessionTemplate;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.boot.web.servlet.FilterRegistrationBean;
  import org.springframework.boot.web.servlet.ServletRegistrationBean;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Primary;
  import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
  import org.springframework.core.io.support.ResourcePatternResolver;
  import org.springframework.jdbc.datasource.DataSourceTransactionManager;
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  import org.springframework.transaction.annotation.TransactionManagementConfigurer;
  
  import javax.sql.DataSource;
  import java.sql.SQLException;
  import java.util.Properties;
  
  @Slf4j
  @Configuration
  public class MyBatisConfig implements TransactionManagementConfigurer {
  
      @Primary
      @Bean(initMethod = "init", destroyMethod = "close")
      @ConfigurationProperties(prefix = "spring.datasource")
      public DataSource dataSource() {
          DruidDataSource datasource = new DruidDataSource();
          try {
              datasource.setFilters("stat,wall,log4j");
          } catch (SQLException e) {
              log.error(e.getMessage());
          }
          return datasource;
      }
  
      private PageHelper pagePlugin() {
          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);
          return pageHelper;
      }
  
  
      @Bean
      public ServletRegistrationBean statViewServlet() {
          ServletRegistrationBean reg = new ServletRegistrationBean();
          reg.setServlet(new StatViewServlet());
          reg.addUrlMappings("/druid/*");
          reg.addInitParameter("loginUsername", "tanguo");
          reg.addInitParameter("loginPassword", "123456");
          return reg;
      }
  
  
      @Bean
      public FilterRegistrationBean filterRegistrationBean() {
          FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
          filterRegistrationBean.setFilter(new WebStatFilter());
          filterRegistrationBean.addUrlPatterns("/*");
          filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
          return filterRegistrationBean;
      }
  
      @Bean(name = "sqlSessionFactory")
      public SqlSessionFactory sqlSessionFactoryBean() {
          return getSqlSessionFactory();
      }
  
      protected SqlSessionFactory getSqlSessionFactory() {
          SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
          bean.setDataSource(dataSource());
          bean.setTypeAliasesPackage("com.transaction.entity");
          bean.setPlugins(new Interceptor[]{pagePlugin()});
          ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
          try {
              bean.setMapperLocations(resolver.getResources("classpath:mapper/**/*.xml"));
              return bean.getObject();
          } catch (Exception e) {
              e.printStackTrace();
              throw new RuntimeException(e);
          }
      }
  
      @Bean
      public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
          return new SqlSessionTemplate(sqlSessionFactory);
      }
  
      @Bean
      @Override
      public PlatformTransactionManager annotationDrivenTransactionManager() {
          return new DataSourceTransactionManager(dataSource());
      }
  
  
      public static void main(String[] args) {
          String str = "05002";
          System.out.println(Integer.parseInt(str));
      }
  }
  
  