自定义工具类封装使用(持续更新)

CommonUtil公具类

checkAllNotBlank(检验多个参数是否为空)

import org.apache.commons.lang3.StringUtils;
/**
 *
 * @author hecc
 * @date 2022/10/24 19:36
 */
public class CommonUtil
{
    /**
     * 当所有参数都不为NULL和空字符串时返回true
     * @param strs
     * @return
     */
    public static boolean checkAllNotBlank(String...strs){
        for(String s : strs){
            if(StringUtils.isBlank(s)){
                return false;
            }
        }
        return true;
    }
}

例子:

if(!CommonUtil.checkAllNotBlank(dto.getObjectId(),dto.getType(),dto.getContent(),dto.getRepresent())){
    throw new BasicExecption("PARAMS_REQUIRED","缺少参数!");
}
posted @ 2022-10-24 19:35  chandol  阅读(24)  评论(0编辑  收藏  举报