Browse Source

fix https://github.com/baomidou/mybatis-plus/issues/4247

VampireAchao 3 years ago
parent
commit
dec385f693

+ 5 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisMapperRegistry.java

@@ -46,9 +46,12 @@ public class MybatisMapperRegistry extends MapperRegistry {
     @Override
     public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
         // TODO 这里换成 MybatisMapperProxyFactory 而不是 MapperProxyFactory
-        final MybatisMapperProxyFactory<T> mapperProxyFactory = (MybatisMapperProxyFactory<T>) knownMappers.get(type);
+        // fix https://github.com/baomidou/mybatis-plus/issues/4247
+        MybatisMapperProxyFactory<T> mapperProxyFactory = (MybatisMapperProxyFactory<T>) knownMappers.get(type);
         if (mapperProxyFactory == null) {
-            throw new BindingException("Type " + type + " is not known to the MybatisPlusMapperRegistry.");
+            mapperProxyFactory = (MybatisMapperProxyFactory<T>) knownMappers.entrySet().stream()
+                .filter(t -> t.getKey().getName().equals(type.getName())).findFirst()
+                .orElseThrow(() -> new BindingException("Type " + type + " is not known to the MybatisPlusMapperRegistry."));
         }
         try {
             return mapperProxyFactory.newInstance(sqlSession);