0
点赞
收藏
分享

微信扫一扫

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

90哦吼 2022-03-30 阅读 27
java后端

在学习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>

学习的过程,记录一下。

举报

相关推荐

0 条评论