Spring Data provides nice template for standard CRUD methods and the default repository implementations provide support for a variety of back-end data stores. This eliminates the need to create boilerplate code in the application and saves a lot of time.
Implement Custom Behavior
But when directly implementing org.springframework.data.repository.Repositoryinterface, two CRUD methods must be provided.
Adding custom behavior to Spring Data repositories
Implement Custom Behavior
interface UserRepositoryCustom { public void someCustomMethod(User user); } class UserRepositoryImpl implements UserRepositoryCustom { public void someCustomMethod(User user) { // Your custom implementation } }Let Spring know about the custom behavior
public interface UserRepository extends JpaRepository<User, Long>, UserRepositoryCustom { // Declare query methods here }
Selective CRUD operations
By default, Spring Data provides the CRUD operations in org.springframework.data.repository.CrudRepository. Implementing this interface allows complete control of these methods.But when directly implementing org.springframework.data.repository.Repositoryinterface, two CRUD methods must be provided.
- findOne
- save
0 comments:
Post a Comment