fix 修复 加解密拦截器null问题

2.X
疯狂的狮子Li 2 years ago
parent d6edc56d0e
commit 4317a1560a

@ -1,6 +1,7 @@
package com.ruoyi.common.encrypt.interceptor; package com.ruoyi.common.encrypt.interceptor;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.encrypt.annotation.EncryptField; import com.ruoyi.common.encrypt.annotation.EncryptField;
import com.ruoyi.common.encrypt.core.EncryptContext; import com.ruoyi.common.encrypt.core.EncryptContext;
@ -55,13 +56,20 @@ public class MybatisDecryptInterceptor implements Interceptor {
* @param sourceObject * @param sourceObject
*/ */
private void decryptHandler(Object sourceObject) { private void decryptHandler(Object sourceObject) {
if (ObjectUtil.isNull(sourceObject)) {
return;
}
if (sourceObject instanceof Map<?, ?>) { if (sourceObject instanceof Map<?, ?>) {
((Map<?, ?>) sourceObject).values().forEach(this::decryptHandler); ((Map<?, ?>) sourceObject).values().forEach(this::decryptHandler);
return; return;
} }
if (sourceObject instanceof List<?>) { if (sourceObject instanceof List<?>) {
List<?> sourceList = (List<?>) sourceObject;
if(CollectionUtil.isEmpty(sourceList)) {
return;
}
// 判断第一个元素是否含有注解。如果没有直接返回,提高效率 // 判断第一个元素是否含有注解。如果没有直接返回,提高效率
Object firstItem = ((List<?>) sourceObject).get(0); Object firstItem = sourceList.get(0);
if (CollectionUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) { if (CollectionUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) {
return; return;
} }

@ -66,13 +66,20 @@ public class MybatisEncryptInterceptor implements Interceptor {
* @param sourceObject * @param sourceObject
*/ */
private void encryptHandler(Object sourceObject) { private void encryptHandler(Object sourceObject) {
if (ObjectUtil.isNull(sourceObject)) {
return;
}
if (sourceObject instanceof Map<?, ?>) { if (sourceObject instanceof Map<?, ?>) {
((Map<?, ?>) sourceObject).values().forEach(this::encryptHandler); ((Map<?, ?>) sourceObject).values().forEach(this::encryptHandler);
return; return;
} }
if (sourceObject instanceof List<?>) { if (sourceObject instanceof List<?>) {
List<?> sourceList = (List<?>) sourceObject;
if(CollectionUtil.isEmpty(sourceList)) {
return;
}
// 判断第一个元素是否含有注解。如果没有直接返回,提高效率 // 判断第一个元素是否含有注解。如果没有直接返回,提高效率
Object firstItem = ((List<?>) sourceObject).get(0); Object firstItem = sourceList.get(0);
if (CollectionUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) { if (CollectionUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) {
return; return;
} }

Loading…
Cancel
Save