1,在mybatis.xml中配置:
<mybatis:scan base-package="com.owen.mybatis.mappers" />
2,在application.xml中配置(Spring):
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="mapperLocations" value="classpath*:mapping/*.xml" />
</bean>
3,在SpringBoot中的两种配置:
a.@MapperScan(value="com.mzqx.springboot.mapper")
b.@Configuration
@AutoConfigureAfter(MybatisConfig.class) //保证在MyBatisConfig实例化之后再实例化该类
public class MapperScannerConfig {
// mapper接口的扫描器
@Bean
public MapperScannerConfigurer mapperScannerConfigurer() {
MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
mapperScannerConfigurer.setBasePackage("com.mzqx.springboot.mapper");
return mapperScannerConfigurer;
}
<mybatis:scan base-package="com.owen.mybatis.mappers" />
2,在application.xml中配置(Spring):
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="mapperLocations" value="classpath*:mapping/*.xml" />
</bean>
3,在SpringBoot中的两种配置:
a.@MapperScan(value="com.mzqx.springboot.mapper")
b.@Configuration
@AutoConfigureAfter(MybatisConfig.class) //保证在MyBatisConfig实例化之后再实例化该类
public class MapperScannerConfig {
// mapper接口的扫描器
@Bean
public MapperScannerConfigurer mapperScannerConfigurer() {
MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
mapperScannerConfigurer.setBasePackage("com.mzqx.springboot.mapper");
return mapperScannerConfigurer;
}
}