这里再提供一个在java中,校验字符串是否为空,校验对象是否为空,校验数组是否为空的工具类代码,完整代码如下:
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import net.srt.framework.common.exception.ServerException;
/**
* 校验工具类
*
*/
public class AssertUtils {
/**
* 校验字符串是否为空
*
* @param str
* @param variable
*/
public static void isBlank(String str, String variable) {
if (StrUtil.isBlank(str)) {
throw new ServerException(variable + "不能为空");
}
}
/**
* 校验对象是否为空
*
* @param object
* @param variable
*/
public static void isNull(Object object, String variable) {
if (object == null) {
throw new ServerException(variable + "不能为空");
}
}
/**
* 校验数组是否为空
*
* @param array
* @param variable
*/
public static void isArrayEmpty(Object[] array, String variable) {
if (ArrayUtil.isEmpty(array)) {
throw new ServerException(variable + "不能为空");
}
}
}








还没有评论,来说两句吧...