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; } }

 

相关文章:

  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
猜你喜欢
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
  • 2022-02-27
相关资源
相似解决方案