自定义断言判断参数是否填写

public class AssertUtil {


    /**
     * 验证输入参数必填项
     *
     */
    public static void assertRequired(String argNames, Object... args) throws Exception {
        boolean isNull = false;
        String[] _argNames = argNames.split(",");
        StringBuffer argName = new StringBuffer("");
        String name = "";
        int index = 0;
        for (Object arg : args) {
            if (null == arg || arg.toString().length() == 0) {
            name = _argNames[index];
                argName.append(name).append(" ");
                isNull = true;
            }
            index++;
        }
        if (isNull) {
            throw new Exception(name + " 为空。");
        }
    }
}

你可能感兴趣的:(自定义断言判断参数是否填写)