فهرست منبع

回滚selectOne查询方式.

https://github.com/baomidou/mybatis-plus/issues/5838
nieqiurong 1 سال پیش
والد
کامیت
077923e497
1فایلهای تغییر یافته به همراه2 افزوده شده و 10 حذف شده
  1. 2 10
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/mapper/BaseMapper.java

+ 2 - 10
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/mapper/BaseMapper.java

@@ -222,21 +222,13 @@ public interface BaseMapper<T> extends Mapper<T> {
      * @param throwEx      boolean 参数,为true如果存在多个结果直接抛出异常
      */
     default T selectOne(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper, boolean throwEx) {
-        List<T> list = new ArrayList<>();
-        //TODO 后期配合Page参数可以做数据库分页,下面的换成RowBounds做限制结果集也行
-        this.selectList(queryWrapper, resultContext -> {
-            T resultObject = resultContext.getResultObject();
-            list.add(resultObject);
-            if (!throwEx || resultContext.getResultCount() > 1) {
-                resultContext.stop();
-            }
-        });
+        List<T> list = this.selectList(queryWrapper);
         int size = list.size();
         if (size == 1) {
             return list.get(0);
         } else if (size > 1) {
             if (throwEx) {
-                throw new TooManyResultsException("Expected one result (or null) to be returned by selectOne(), but found multiple records");
+                throw new TooManyResultsException("Expected one result (or null) to be returned by selectOne(), but found: " + list.size());
             }
             return list.get(0);
         }