update 优化 encrypt 加解密模块语法 简化代码消除警告
This commit is contained in:
parent
3baad24912
commit
cb80568828
@ -7,6 +7,7 @@ import com.ruoyi.common.encrypt.properties.EncryptorProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
@ -16,6 +17,7 @@ import org.springframework.context.annotation.Bean;
|
||||
* @version 4.6.0
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(EncryptorProperties.class)
|
||||
@ConditionalOnProperty(value = "mybatis-encryptor.enable", havingValue = "true")
|
||||
public class EncryptorAutoConfiguration {
|
||||
|
||||
|
@ -55,17 +55,17 @@ public class MybatisDecryptInterceptor implements Interceptor {
|
||||
* @param sourceObject 待加密对象
|
||||
*/
|
||||
private void decryptHandler(Object sourceObject) {
|
||||
if (sourceObject instanceof Map) {
|
||||
((Map<?, Object>) sourceObject).values().forEach(this::decryptHandler);
|
||||
if (sourceObject instanceof Map<?, ?> map) {
|
||||
map.values().forEach(this::decryptHandler);
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof List) {
|
||||
if (sourceObject instanceof List<?> list) {
|
||||
// 判断第一个元素是否含有注解。如果没有直接返回,提高效率
|
||||
Object firstItem = ((List<?>) sourceObject).get(0);
|
||||
Object firstItem = list.get(0);
|
||||
if (CollectionUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) {
|
||||
return;
|
||||
}
|
||||
((List<?>) sourceObject).forEach(this::decryptHandler);
|
||||
list.forEach(this::decryptHandler);
|
||||
return;
|
||||
}
|
||||
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
||||
|
@ -49,9 +49,8 @@ public class MybatisEncryptInterceptor implements Interceptor {
|
||||
|
||||
@Override
|
||||
public Object plugin(Object target) {
|
||||
if (target instanceof ParameterHandler) {
|
||||
if (target instanceof ParameterHandler parameterHandler) {
|
||||
// 进行加密操作
|
||||
ParameterHandler parameterHandler = (ParameterHandler) target;
|
||||
Object parameterObject = parameterHandler.getParameterObject();
|
||||
if (ObjectUtil.isNotNull(parameterObject) && !(parameterObject instanceof String)) {
|
||||
this.encryptHandler(parameterObject);
|
||||
@ -65,19 +64,18 @@ public class MybatisEncryptInterceptor implements Interceptor {
|
||||
*
|
||||
* @param sourceObject 待加密对象
|
||||
*/
|
||||
@SuppressWarnings("unchecked cast")
|
||||
private void encryptHandler(Object sourceObject) {
|
||||
if (sourceObject instanceof Map) {
|
||||
((Map<?, Object>) sourceObject).values().forEach(this::encryptHandler);
|
||||
if (sourceObject instanceof Map<?, ?> map) {
|
||||
map.values().forEach(this::encryptHandler);
|
||||
return;
|
||||
}
|
||||
if (sourceObject instanceof List) {
|
||||
if (sourceObject instanceof List<?> list) {
|
||||
// 判断第一个元素是否含有注解。如果没有直接返回,提高效率
|
||||
Object firstItem = ((List<?>) sourceObject).get(0);
|
||||
Object firstItem = list.get(0);
|
||||
if (CollectionUtil.isEmpty(encryptorManager.getFieldCache(firstItem.getClass()))) {
|
||||
return;
|
||||
}
|
||||
((List<?>) sourceObject).forEach(this::encryptHandler);
|
||||
list.forEach(this::encryptHandler);
|
||||
return;
|
||||
}
|
||||
Set<Field> fields = encryptorManager.getFieldCache(sourceObject.getClass());
|
||||
|
@ -4,7 +4,6 @@ import com.ruoyi.common.encrypt.enumd.AlgorithmType;
|
||||
import com.ruoyi.common.encrypt.enumd.EncodeType;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 加解密属性配置类
|
||||
@ -13,7 +12,6 @@ import org.springframework.stereotype.Component;
|
||||
* @version 4.6.0
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "mybatis-encryptor")
|
||||
public class EncryptorProperties {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user