java / beginner
Snippet
Spring Data JPA Repository
Spring Data JPA allows you to create data access layers by simply defining an interface. It automatically generates SQL queries based on method names.
snippet.java
1
2
3
4
@Repositorypublic interface ProductRepository extends JpaRepository<Product, Long> {List<Product> findByName(String name);}
spring
Breakdown
1
@Repository
Marks the interface as a Data Access Object (DAO) that handles database interactions.
2
extends JpaRepository<Product, Long>
Inherits standard CRUD operations for the Product entity with a Long ID type.
3
findByName(String name)
A derived query method that automatically generates a 'SELECT' query based on the 'name' field.