ProductRepository.java
spring_boot/code/advanced/src/main/java/com/example/demo/repository/ProductRepository.java
package com.example.demo.repository;
import com.example.demo.entity.Product;
import org.springframework.data.jpa.repository.JpaRepository;
import java.math.BigDecimal;
import java.util.List;
/**
* Spring Data JPA repository for {@link com.example.demo.entity.Product}.
* <p>
* Extending {@link JpaRepository} provides standard CRUD methods (findById, save, delete, etc.)
* without implementation. Method names follow the "derived query" convention: Spring generates
* the query from the method name (e.g. findByNameContainingIgnoreCase → WHERE LOWER(name) LIKE %?%).
*/
public interface ProductRepository extends JpaRepository<Product, Long> {
/**
* Find all products whose name contains the given string (case-insensitive).
* Generated query: WHERE LOWER(name) LIKE LOWER('%' || ?1 || '%')
*
* @param name the substring to search for (e.g. "laptop")
* @return list of matching products
*/
List<Product> findByNameContainingIgnoreCase(String name);
/**
* Find all products with price between min and max (inclusive).
* Generated query: WHERE price BETWEEN ?1 AND ?2
*
* @param min minimum price
* @param max maximum price
* @return list of matching products
*/
List<Product> findByPriceBetween(BigDecimal min, BigDecimal max);
/**
* Check whether a product with the given name already exists.
* Generated query: SELECT COUNT(*) > 0 WHERE name = ?1
*
* @param name product name
* @return true if a product with this name exists
*/
boolean existsByName(String name);
}
Artículos relacionados
DemoApplication.java
DemoApplication.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/DemoApplication.java).
Leer artículo →CustomHealthIndicator.java
CustomHealthIndicator.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/actuator/CustomHealthIndicator.java).
Leer artículo →SecurityConfig.java
SecurityConfig.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/config/SecurityConfig.java).
Leer artículo →ProductController.java
ProductController.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/controller/ProductController.java).
Leer artículo →PublicController.java
PublicController.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/controller/PublicController.java).
Leer artículo →ProductCreateRequest.java
ProductCreateRequest.java — java source code from the spring boot learning materials (spring_boot/code/advanced/src/main/java/com/example/demo/dto/ProductCreateRequest.java).
Leer artículo →