瀏覽代碼

Merge branch '3.0' into github3.0

hubin 3 年之前
父節點
當前提交
4273be6396

+ 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);

+ 4 - 2
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/toolkit/SimpleQuery.java

@@ -3,9 +3,11 @@ package com.baomidou.mybatisplus.extension.toolkit;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
 import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 import org.apache.ibatis.session.SqlSession;
+import org.mybatis.spring.SqlSessionUtils;
 
 import java.util.*;
 import java.util.function.*;
@@ -314,14 +316,14 @@ public class SimpleQuery {
      * @param <E>         实体类型
      * @return 查询列表结果
      */
-    private static <E> List<E> selectList(Class<E> entityClass, LambdaQueryWrapper<E> wrapper) {
+    public static <E> List<E> selectList(Class<E> entityClass, LambdaQueryWrapper<E> wrapper) {
         SqlSession sqlSession = SqlHelper.sqlSession(entityClass);
         List<E> result;
         try {
             BaseMapper<E> userMapper = SqlHelper.getMapper(entityClass, sqlSession);
             result = userMapper.selectList(wrapper);
         } finally {
-            sqlSession.close();
+            SqlSessionUtils.closeSqlSession(sqlSession, GlobalConfigUtils.currentSessionFactory(entityClass));
         }
         return result;
     }