Java随笔

 

Java验证传参是否为空工具类

public static void notNull(Object obj, String msgKey, Object... args) {
        if (obj instanceof String) {
            notEmpty((String) obj,msgKey);
        }else if(obj instanceof List){
            notListEmpty((List) obj,msgKey);
        }else if(obj == null){
            fail(msgKey, args);
        }
    }

 

public static void notEmpty(String str, String msgKey, Object... args) {
		if (str == null || str.isEmpty()) {
			fail(msgKey, args);
		}
	}

  

@SuppressWarnings("rawtypes")
	public static void notListEmpty(List lst, String msgKey, Object... args) {
		if (lst == null || lst.isEmpty()) {
			fail(msgKey, args);
		}
	}

  

private static void fail(String msgKey, Object... args) {
		throw new ServiceException(msgKey);
	}

  

posted @ 2019-04-10 14:43  砖治不服  阅读(127)  评论(0编辑  收藏  举报