Skip to content

Instantly share code, notes, and snippets.

@sksaikia
Created February 23, 2021 14:37
public Product getProductById(Long productId) throws ProductNotExistException {
Optional<Product> optionalProduct = productRepository.findById(productId);
if (!optionalProduct.isPresent())
throw new ProductNotExistException("Product id is invalid " + productId);
return optionalProduct.get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment