SpringBoot整合Mybatis,application.properties里面mybatis.type-aliases-package配置失败的问题

在应用MyBatis时,使用对象关系映射,将对象和Aliase映射起来。

在Mybatis的文档明确写出,如果你没有明确定义实体类的Aliase,框架会自动将Class Name自动 作为别名。

在学习SpringBoot整合Mybatis的时候想通过application.properties里面配置mybatis.type-aliases-package来自动加载实体类到Aliases,这样子直接可以在parameterType和resultType写类名就行了。

以前用SpringMVC整合Mybatis的时候通过配置文件直接可以用,觉得挺好用的,现在用SpringBoot的时候居然用不了了,网上各种找也是直接配置mybatis.type-aliases-package就可以了。后面看到这篇文章:

SpringBoot整合Mybatis,TypeAliases配置失败的问题

发现自己做多数据源配置时进行了设置,所以在application.properties里面配置不生效

mybatis.type-aliases-package=com.xxx.xxx.entity

果断不在这里配置,在多数据源配置里面加上

bean.setTypeAliasesPackage("com.xxx.xxx.entity");

在test.xml里面使用

 <select id="getTestList" parameterType="test" resultType="test">
 	select * from t_test
 </select>

查询的时候出来结果了。当然entity下面也要有Test.java这个类才行
以前的写法是

<select id="getTestList" parameterType="com.xxx.xxx.entity.Test" resultType="com.xxx.xxx.entity.Test">
	select * from t_test
</select>

学习的过程,记录一下。


版权声明:本文为m0_67392811原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。