CrudRepository is a Spring Data interface for common create, read, update, and delete operations. Instead of writing a persistence class, declare an interface that extends CrudRepository. Spring Data creates its implementation when the application starts. section 3.2.2
Listing 3.13 Defining a repository interface for persisting ingredients
package tacos.data;
import org.springframework.data.repository.CrudRepository;
import tacos.Ingredient;
public interface IngredientRepository
extends CrudRepository<Ingredient, String> {
}
IngredientRepository needs no method declarations to gain the standard operations. In CrudRepository<Ingredient, String>, Ingredient is the object being stored and String is its ID type. section 3.2.2
An order repository follows the same pattern: CrudRepository<TacoOrder, Long>. Prepare the domain objects for persistence, including their IDs, then inject the repositories where the application needs them. This replaces explicit JdbcTemplate repository implementations while providing additional standard operations. section 3.2.2 section 3.2.3
Add a query beyond basic CRUD
Declare List<TacoOrder> findByDeliveryZip(String deliveryZip); in OrderRepository. Spring Data reads the method name as a request to find TacoOrder objects whose deliveryZip property matches the argument and generates the query implementation. section 3.3.4
The interface pattern carries across Spring Data JDBC, JPA, Cassandra, and MongoDB. Check the ID type when changing databases: the order example uses Long with JPA, UUID with Cassandra, and String with MongoDB. Domain mapping can change even when the repository interface barely does. section 4.1.4 section 4.2.3

