mybatis:使用带有XML配置的mapper接口来获取全局参数 [英] mybatis: Using mapper interfaces with XML config for global parameters

查看:556
本文介绍了mybatis:使用带有XML配置的mapper接口来获取全局参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢XML表示法来指定全局参数,例如连接字符串。我也喜欢Mapper注释。当我尝试将两者合并时,我得到这个例外

I like the XML notation for specifying global parameters such as connection strings. I also like Mapper annotations. When I try to combine the two, I get this exception.

有没有办法将两者结合起来?我想将一个XML文件用于全局配置,但让mybatis考虑Mapper接口。

Is there a way to combine the two? I would like to use an XML file for the global configurations, but have mybatis take Mapper interfaces into account.

问题是SqlSessionFactoryBuilder()。build()需要一个Reader(我想用它来传递XML配置),或者一个Configuration对象(我​​看到它有 addMappers()方法可以帮助我) - 但我不明白如何将两者结合起来。

The problem is that SqlSessionFactoryBuilder().build() takes either a Reader (which I want to use to pass the XML config), or a Configuration object (which I see has the addMappers() method that can help me) - but I don't understand how to combine the two.

推荐答案

factory.getConfiguration()。addMapper(。 ..);

这篇关于mybatis:使用带有XML配置的mapper接口来获取全局参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆