# mybatis2021 **Repository Path**: webrx/mybatis2021 ## Basic Information - **Project Name**: mybatis2021 - **Description**: mybatis2021-code - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2021-07-20 - **Last Updated**: 2022-04-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mybatis 2021 案例项目代码 ```java /* * Copyright (c) 2006, 2021, webrx.cn All rights reserved. * */ package cn.webrx.config; import com.alibaba.druid.pool.DruidDataSource; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.*; import org.springframework.core.env.Environment; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import javax.sql.DataSource; import java.io.IOException; /** *
Project: mybatis2021 - cn.webrx.config.SpringConfig *
Powered by webrx On 2021-07-19 16:31:57 *
Created by IntelliJ IDEA * * @author webrx [webrx@126.com] * @version 1.0 * @since 15 */ @Configuration @ComponentScan(basePackages = {"cn.webrx.mapper", "cn.webrx.entity"}) @Import({DruidConfig.class}) public class cn.webrx.config.SpringConfig { @Bean("sf") public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource ds) throws IOException { SqlSessionFactoryBean sf = new SqlSessionFactoryBean(); sf.setDataSource(ds); sf.setTypeAliasesPackage("cn.webrx.entity"); //设置mybatis mapper xml 文件位置 resources/mappers/*.xml sf.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mappers/*.xml")); return sf; } @Bean public MapperScannerConfigurer mapperScannerConfigurer() { MapperScannerConfigurer msc = new MapperScannerConfigurer(); msc.setSqlSessionFactoryBeanName("sf"); msc.setBasePackage("cn.webrx.mapper"); return msc; } } ```