| | |
| | | package com.mes.common.config; |
| | | |
| | | import com.alibaba.druid.pool.DruidDataSource; |
| | | import com.baomidou.mybatisplus.annotation.DbType; |
| | | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
| | | import org.apache.ibatis.session.SqlSessionFactory; |
| | | import org.mybatis.spring.SqlSessionFactoryBean; |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.sql.DataSource; |
| | | |
| | | |
| | | /** |
| | |
| | | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
| | | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); |
| | | return interceptor; |
| | | } |
| | | |
| | | @Resource |
| | | private DataSourceProperties dataSourceProperties; |
| | | |
| | | |
| | | @Bean(name = "dataSource") |
| | | public DataSource dataSource() { |
| | | |
| | | DruidDataSource dataSource = new DruidDataSource(); |
| | | dataSource.setUrl(dataSourceProperties.getUrl()); |
| | | dataSource.setDriverClassName(dataSourceProperties.getDriverClassName()); |
| | | dataSource.setUsername(dataSourceProperties.getUsername()); |
| | | dataSource.setPassword(dataSourceProperties.getPassword()); |
| | | |
| | | return dataSource; |
| | | |
| | | } |
| | | |
| | | public SqlSessionFactory sqlSessionFactory() throws Exception { |
| | | SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); |
| | | sqlSessionFactoryBean.setDataSource(dataSource()); |
| | | return sqlSessionFactoryBean.getObject(); |
| | | } |
| | | |
| | | } |