参数批量验证
package com.oa.common.messageCenter;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class ParamsValidator{
private Map<String,String> map = new HashMap<>();
public static ParamsValidator getInstance() {
return new ParamsValidator();
}
public ParamsValidator put (String param,String ParamName) {
map.put(ParamName, param);
return this;
}
public String validator() throws Exception {
for(Entry<String,String> entry:map.entrySet()) {
if (isEmpty(entry.getValue())) {
return "参数[" + entry.getKey() + "]不能为空";
}
}
return null;
}
public String toString(Object obj) {
return obj == null ? "" :obj.toString();
}
@SuppressWarnings("all")
private boolean isEmpty(Collection collection) {
return collection == null || collection.isEmpty();
}
@SuppressWarnings("all")
private boolean isEmpty(Map map) {
return map == null || map.isEmpty();
}
private boolean isEmpty(String str) {
return str == null || str.isEmpty();
}
@SuppressWarnings("all")
private boolean isEmpty(Object obj) {
return toString(obj).isEmpty();
}
@SuppressWarnings("all")
private boolean isEmptyTrim(Object obj) {
return toString(obj).trim().isEmpty();
}
public <T> boolean isEmpty(T[] array) {
return array == null || array.length == 0;
}
}