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() {
}
}
klasa CustomerRepositoryImpl powinny wdrożyć CustomCustomerRepository nie CustomerRepository jako jedyna metoda CustomCustomerRepository wymaga realizacja –
to działa CustomCustomerRepositoryImpl bez customMethod()? –