Java随笔
Java验证传参是否为空工具类
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。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); }

更多精彩