package com.yonge.cooleshow.biz.dal.config;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.MybatisXMLLanguageDriver;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @author hgw
 * Created by 2021-12-02
 */
@Configuration
public class MyBatisPlusConfig {

    @Autowired
    private MybatisPlusProperties plusProperties;

    /**
     * 分页插件
     */
    @Bean
    @Primary
    public PaginationInterceptor paginationInterceptor() {
        plusProperties.setMapperLocations(new String[]{"classpath*:config/mybatis/*.xml"});
        plusProperties.setTypeAliasesPackage("com.yonge.cooleshow.biz.dal.entity");
        MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
        mybatisConfiguration.setMapUnderscoreToCamelCase(true);
        mybatisConfiguration.setCacheEnabled(false);
        plusProperties.setConfiguration(mybatisConfiguration);
        return new PaginationInterceptor();
    }
}
