2015-06-16 25 views

Odpowiedz

9

Użytkownik zdefiniowałby CustomRepository do obsługi takich scenariuszy. Rozważ, że masz CustomerRepository, który rozszerza domyślne dane sprężyny Interfejs JPA JPARepository<Customer,Long>

Utwórz nowy interfejs CustomCustomerRepository z niestandardowym podpisem metody.

public interface CustomCustomerRepository { 
    public void customMethod(); 
} 

Extend CustomerRepository interfejsu za pomocą CustomCustomerRepository

public interface CustomerRepository extends JpaRepository<Customer, Long>, CustomCustomerRepository{ 

} 

Utwórz klasę realizacji nazwie CustomerRepositoryImpl który implementuje CustomerRepository. Tutaj możesz wstrzyknąć EntityManager używając @PersistentContext. Konwencje nazewnictwa mają tu znaczenie.

public class CustomCustomerRepositoryImpl implements CustomCustomerRepository { 

    @PersistenceContext 
    private EntityManager em; 

    @Override 
    public void customMethod() { 

    } 
} 
+1

klasa CustomerRepositoryImpl powinny wdrożyć CustomCustomerRepository nie CustomerRepository jako jedyna metoda CustomCustomerRepository wymaga realizacja –

+0

to działa CustomCustomerRepositoryImpl bez customMethod()? –