本文基于之前的《基于H2的Mybatis单元测试》,当使用mybatis-plus和mybatis-plus-join时如何进行单元测试
改动点
支持mybatis-plus
- 将相关类修改为mybatis-plus的类,如
MybatisConfiguration、MybatisSqlSessionFactoryBuilder
支持mybatis-plus-join
- 在执行
addMapper前,插入MPJInterceptor和MPJSqlInjector
代码示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| MapperRegistry mapperRegistry = configuration.getMapperRegistry();
configuration.addInterceptor(new MPJInterceptor()); GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration); globalConfig.setSqlInjector(new MPJSqlInjector());
mapperRegistry.addMapper(mapperClass); if (mapperXml != null) { parse(configuration, mapperXml); }
|