You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
741 B

package cn.teammodel.utils;
import cn.teammodel.common.ErrorCode;
import cn.teammodel.config.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import java.util.List;
/**
* @author winter
* @create 2023-11-29 15:41
*/
@Slf4j
public class RepositoryUtil {
/**
* ,listlist1,
*/
public static <T> T findOne(List<T> list, String errorMsg) {
if (ObjectUtils.isEmpty(list) || list.size() > 1) {
log.error("查询结果为空或数量 > 1");
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), errorMsg);
}
return list.get(0);
}
}