typeAliasesPackage 配置

mybatis 的 xml 文件中需要写类的全限定名,较繁琐,可以配置自动扫描包路径给类配置别名,有两种配置方式。

方式一:

mybatis-config.xml 中配置

<typeAliases>
  <package name="top.jimc.ssm.model"/>
</typeAliases>

此配置不支持多路径配置,不支持通配符配置,不灵活。

方式二:

SqlSessionFactory 中配置 typeAliasesPackage 属性

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
    <property name="typeAliasesPackage" value="top.jimc.ssm.model,top.jimc.test.model"/>
    <property name="mapperLocations">
        <list>
            <value>classpath*:mapper/**/*.xml</value>
        </list>
    </property>
</bean>
原文地址:https://www.cnblogs.com/Jimc/p/9778595.html