spring常用工具类

一、org.springframework.util.Assert:

它断定某一个实际的运行值和预期想一样,否则就抛出异常。Spring 对方法入参的检测借用了这个概念,其提供的Assert 类拥有众多按规则对方法入参进行断言的方法,可以满足大部分方法入参检测的要求。这些断言方法在入参不满足要求时就会抛出
IllegalArgumentException。

例:

public Boolean exportCrowd(QueryCrowdExport obj) {
		Assert.notNull(obj);
		Assert.notNull(obj.getCrowdId());
		Assert.notNull(obj.getExportType());
		
    	//crowdId获得crowd记录
		Crowd crowd = new Crowd();
		crowd = crowdService.queryCrowdById(obj.getCrowdId());
    	//校验
    	if(ObjectUtils.isEmpty(crowd)==true) {
    		return false;
    	}
    	//添加job、更新标志
    	Boolean res = false;
    	if(obj.getExportType().equals("CC")) {
    		res = jobService.addCCJob(crowd);
    		if(res==true) {
    			crowd.setCcExported(true);
    			crowdMapper.updateByPrimaryKeySelective(crowd);
    		}
    	}else if(obj.getExportType().equals("CIA")) {
    		res = jobService.addCIAJob(crowd,obj);
    		if(res==true) {
    			crowd.setCiaExported(true);
    			crowdMapper.updateByPrimaryKeySelective(crowd);
    		}
    	}	
    	return res;
    }

猜你喜欢

转载自blog.csdn.net/w_t_y_y/article/details/79925930