判断javabean 是否有属性为空

public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
        SearchBaseBean baseBean = new SearchBaseBean();
        Class class1 = baseBean.getClass();
        Field[] fileds = class1.getDeclaredFields();
        for (int i = 0; i < fileds.length; i++) {
            Field field = fileds[i];
            String fieldName = field.getName();

        }

        Method[] sourceMethods = class1.getMethods();
        for (int i = 0; i < sourceMethods.length; i++) {
            if (sourceMethods[i].getName().startsWith("get")) {
                String fieldName = sourceMethods[i].getName().substring(3) ;
                Object value = sourceMethods[i].invoke(baseBean,null);
                System.out.println(value);
            }
        }

    }

你可能感兴趣的:(判断javabean 是否有属性为空)