public class ObjectFieldIsNotNullUtil { public static void main(String[] args) { UserVO vo = new UserVO(); vo.setToken("1"); vo.setUserid("1"); boolean b = notNull(vo,"token"); System.out.println(b); } /** * 判断一个对象的属性有无值 * @param o * @param as 需要过滤的属性,逗号分隔 * @return */ public static boolean notNull(Object o,String as){ try { for(Field f : o.getClass().getDeclaredFields()){ f.setAccessible(true); Object o1 = f.get(o); if(o1!=null && !"".equals(o1)&& !as.contains(f.getName())){ return true; } } }catch (Exception e){ return false; } return false; } }