|
@@ -1,12 +1,12 @@
|
|
|
package com.flow.common.mybatis.handler;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import org.apache.ibatis.reflection.MetaObject;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @author caixiaofeng
|
|
@@ -30,9 +30,8 @@ public class FieldMetaObjectHandler implements MetaObjectHandler {
|
|
|
}
|
|
|
if (metaObject.hasSetter("createdBy")) {
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
- String username = authentication.getName();
|
|
|
- if (StringUtils.isNotBlank(username)) {
|
|
|
- this.fillStrategy(metaObject, "createdBy", username);
|
|
|
+ if (Objects.nonNull(authentication)) {
|
|
|
+ this.fillStrategy(metaObject, "createdBy", authentication.getName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -50,9 +49,8 @@ public class FieldMetaObjectHandler implements MetaObjectHandler {
|
|
|
}
|
|
|
if (metaObject.hasSetter("updatedBy")) {
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
- String username = authentication.getName();
|
|
|
- if (StringUtils.isNotBlank(username)) {
|
|
|
- this.fillStrategy(metaObject, "updatedBy", username);
|
|
|
+ if (Objects.nonNull(authentication)) {
|
|
|
+ this.fillStrategy(metaObject, "updatedBy", authentication.getName());
|
|
|
}
|
|
|
}
|
|
|
}
|