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