From c2e28b5d94914426ca2d4dd9c4002b23c7db1295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Thu, 16 Dec 2021 10:54:26 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BF=AE=E6=94=B9=20=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E6=96=B9=E6=B3=95=E8=BF=94=E5=9B=9E=E7=A9=BA=E5=88=A4?= =?UTF-8?q?=E6=96=AD=20=E4=BC=98=E5=8C=96=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/mybatisplus/core/BaseMapperPlus.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/BaseMapperPlus.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/BaseMapperPlus.java index 9d51d243f..e11ec94ec 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/BaseMapperPlus.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/BaseMapperPlus.java @@ -1,5 +1,7 @@ package com.ruoyi.common.core.mybatisplus.core; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -30,6 +32,9 @@ public interface BaseMapperPlus extends BaseMapper { */ default V selectVoById(Serializable id, Class voClass){ T obj = this.selectById(id); + if (ObjectUtil.isNull(obj)) { + return null; + } return BeanCopyUtils.copy(obj, voClass); } @@ -38,8 +43,8 @@ public interface BaseMapperPlus extends BaseMapper { */ default List selectVoBatchIds(Collection idList, Class voClass){ List list = this.selectBatchIds(idList); - if (list == null) { - return null; + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); } return BeanCopyUtils.copyList(list, voClass); } @@ -49,8 +54,8 @@ public interface BaseMapperPlus extends BaseMapper { */ default List selectVoByMap(Map map, Class voClass){ List list = this.selectByMap(map); - if (list == null) { - return null; + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); } return BeanCopyUtils.copyList(list, voClass); } @@ -60,6 +65,9 @@ public interface BaseMapperPlus extends BaseMapper { */ default V selectVoOne(Wrapper wrapper, Class voClass) { T obj = this.selectOne(wrapper); + if (ObjectUtil.isNull(obj)) { + return null; + } return BeanCopyUtils.copy(obj, voClass); } @@ -68,8 +76,8 @@ public interface BaseMapperPlus extends BaseMapper { */ default List selectVoList(Wrapper wrapper, Class voClass) { List list = this.selectList(wrapper); - if (list == null) { - return null; + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); } return BeanCopyUtils.copyList(list, voClass); } @@ -80,6 +88,9 @@ public interface BaseMapperPlus extends BaseMapper { default > P selectVoPage(IPage page, Wrapper wrapper, Class voClass) { IPage pageData = this.selectPage(page, wrapper); IPage voPage = new Page<>(pageData.getCurrent(), pageData.getSize(), pageData.getTotal()); + if (CollUtil.isEmpty(pageData.getRecords())) { + return (P) voPage; + } voPage.setRecords(BeanCopyUtils.copyList(pageData.getRecords(), voClass)); return (P) voPage; }