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>