package com.example.demo.utils;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
public class CheckObjectFieldIsNullUtils {
/** 日志打印 */
private static Logger LOGGER = LoggerFactory.getLogger(CheckObjectFieldIsNullUtils.class);
/**
* 检查对象属性值是否为字符串"null"或"undefined"
* @param o 对象
* @return boolean false/true
* @throws IllegalAccessException
*/
public static boolean checkObjectFieldIsNull(Object o) throws IllegalAccessException {
LOGGER.info("object: " + JSON.toJSONString(o));
for(Field f : o.getClass().getDeclaredFields()){
f.setAccessible(true);
if (f.get(o) == null) {
continue;
}
if(f.get(o).equals("null") || f.get(o).equals("undefined")) {
LOGGER.info("属性名: " + f.getName());
return true;
}
}
return false;
}
}
Java 检查对象中属性值是否为字符串“null“或“undefined“
最新推荐文章于 2022-04-30 09:45:26 发布