From 43901370e943d04d75e756e9938c5f14d915db7f 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: Wed, 4 Aug 2021 18:13:11 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=BC=BA=E5=88=B6=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=20=E6=97=A0=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=20null=20=E5=B9=B6=E6=97=A5=E5=BF=97=E6=8A=A5?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreateAndUpdateMetaObjectHandler.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/mybatisplus/CreateAndUpdateMetaObjectHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/mybatisplus/CreateAndUpdateMetaObjectHandler.java index 20439da6c..c41602051 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/mybatisplus/CreateAndUpdateMetaObjectHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/mybatisplus/CreateAndUpdateMetaObjectHandler.java @@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.exception.CustomException; import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.StringUtils; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.reflection.MetaObject; @@ -25,14 +24,10 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { try { //根据属性名字设置要填充的值 if (metaObject.hasGetter("createTime")) { - if (StringUtils.isEmpty(metaObject.getValue("createTime"))) { - this.setFieldValByName("createTime", new Date(), metaObject); - } + this.setFieldValByName("createTime", new Date(), metaObject); } if (metaObject.hasGetter("createBy")) { - if (StringUtils.isEmpty(metaObject.getValue("createBy"))) { - this.setFieldValByName("createBy", getLoginUsername(), metaObject); - } + this.setFieldValByName("createBy", getLoginUsername(), metaObject); } } catch (Exception e) { throw new CustomException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); @@ -43,14 +38,10 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { public void updateFill(MetaObject metaObject) { try { if (metaObject.hasGetter("updateBy")) { - if (StringUtils.isEmpty(metaObject.getValue("updateBy"))) { - this.setFieldValByName("updateBy", getLoginUsername(), metaObject); - } + this.setFieldValByName("updateBy", getLoginUsername(), metaObject); } if (metaObject.hasGetter("updateTime")) { - if (StringUtils.isEmpty(metaObject.getValue("updateTime"))) { - this.setFieldValByName("updateTime", new Date(), metaObject); - } + this.setFieldValByName("updateTime", new Date(), metaObject); } } catch (Exception e) { throw new CustomException("自动注入异常 => " + e.getMessage(), HttpStatus.HTTP_UNAUTHORIZED); @@ -65,7 +56,7 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler { try { loginUser = SecurityUtils.getLoginUser(); } catch (Exception e) { - log.warn("自动注入警告 => 用户未登录"); + log.error("自动注入警告 => 用户未登录"); return null; } return loginUser.getUsername();