package com.hzdaba.config.myBatis;
import org.springframework.context.annotation.Bean;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;
import java.util.Properties;
public class MyBatisConfig {
@Bean
public MapperScannerConfigurer mapperScannerConfigurer() {
MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
mapperScannerConfigurer.setBasePackage("classpath:mapper");
Properties propertiesMapper = new Properties();
propertiesMapper.setProperty("mappers", "tk.mybatis.mapper.common.Mapper");
propertiesMapper.setProperty("IDENTITY", "SELECT REPLACE(UUID(),''-'','''')");
propertiesMapper.setProperty("ORDER", "BEFORE");
mapperScannerConfigurer.setProperties(propertiesMapper);
return mapperScannerConfigurer;
}
}
本文介绍了一个使用Spring框架配置MyBatis的示例,通过MapperScannerConfigurer组件自动扫描指定包下的Mapper接口,实现了数据库操作类的自动化配置。文中详细展示了如何设置基础包路径以及自定义属性,如UUID生成策略等。

1512

被折叠的 条评论
为什么被折叠?



