All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yun.util.querydsl.JrpUtil Maven / Gradle / Ivy

There is a newer version: 0.0.31
Show newest version
package com.yun.util.querydsl;

/**
 * @author: yun
 * @createdOn: 2019/11/8 14:21.
 */

import com.yun.util.common.CommonException;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public class JrpUtil {
    public static  T1 findById(JpaRepository jrp, T2 itemId) {
        return findById(jrp, itemId, null);
    }

    public static  T1 findById(JpaRepository jrp, T2 itemId, String err) {
        if (itemId == null) {
            if (err != null) {
                throw CommonException.comEp(err);
            }

            return null;
        }

        Optional optItem = jrp.findById(itemId);
        if (optItem.isPresent()) {
            return optItem.get();
        }

        if (err != null) {
            throw CommonException.comEp(err);
        }

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy