Skip to content

Commit

Permalink
winSecurity优化 动态查询bug 防止空字符串造成的初始化值
Browse files Browse the repository at this point in the history
  • Loading branch information
dongxl committed Dec 11, 2018
1 parent df40fe6 commit 6d3a6b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.winbaoxian.module.security.utils;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
Expand All @@ -11,18 +12,24 @@
* @date 2018-12-11 17:20
*/
public enum MapFastUtils {

INSTANCE;

public static final String NULL_VALUE = "null";

public Map valueEmptyToNull(Map map) {
for (Object k : map.keySet()) {
if (MapUtils.isEmpty(map)) {
return null;
}
Object[] keys = map.keySet().toArray();
for (Object k : keys) {
Object v = map.get(k);
if (v == null) {
continue;
} else if (v instanceof String && StringUtils.isBlank((CharSequence) v)) {
map.replace(k, null);
continue;
map.remove(k);
} else if (v instanceof CharSequence && (StringUtils.isBlank((CharSequence) v) || StringUtils.equalsIgnoreCase(NULL_VALUE, (CharSequence) v))) {
map.remove(k);
} else if (v instanceof Collection && CollectionUtils.isEmpty((Collection) v)) {
map.replace(k, null);
continue;
map.remove(k);
}
}
return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private <T> Predicate getPredicateBySearchParam(Object queryParam, Field field,
if (value instanceof Collection && CollectionUtils.isEmpty((Collection) value)) {
return null;
}
if (value instanceof String && StringUtils.isBlank((CharSequence) value)) {
if (value instanceof CharSequence && StringUtils.isBlank((CharSequence) value)) {
return null;
}
Predicate predicate = null;
Expand Down

0 comments on commit 6d3a6b7

Please sign in to comment.