mybatis-plus自动配置mapperLocations,但mybatis没有,仍需要自己配置
截取部分mybatis-plus源码可见底层帮我们配置了映射文件的默认地址classpath*:/mapper/**/*.xml,我们只需要在类路径(resource目录)下创建mapper文件夹,然后把映射文件xxxMapper.xml放到里面就可以
public class MybatisPlusProperties {
private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver ( ) ;
private String configLocation;
private String [ ] mapperLocations = new String [ ] { "**classpath*:/mapper/**/*.xml**" } ;
private String typeAliasesPackage;
private Class < ? > typeAliasesSuperType;
private String typeHandlersPackage;
private boolean checkConfigLocation = false ;
private ExecutorType executorType;
private Class < ? extends LanguageDriver > defaultScriptingLanguageDriver;
private Properties configurationProperties;
@NestedConfigurationProperty
private MybatisConfiguration configuration;
private String typeEnumsPackage;
@NestedConfigurationProperty
private GlobalConfig globalConfig = GlobalConfigUtils . defaults ( ) ;
mybatis源码则没有帮我们配置默认映射文件
public class MybatisProperties {
public static final String MYBATIS_PREFIX = "mybatis" ;
private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver ( ) ;
private String configLocation;
* * private String [ ] mapperLocations; * *
private String typeAliasesPackage;
private Class < ? > typeAliasesSuperType;
private String typeHandlersPackage;
private boolean checkConfigLocation = false ;
private ExecutorType executorType;
private Class < ? extends LanguageDriver > defaultScriptingLanguageDriver;
private Properties configurationProperties;
@NestedConfigurationProperty
private Configuration configuration;
所以使用mybatis时需要自己配置
mybatis :
mapper-locations : mapper/*.xml