rob*_*del 15 spring-data spring-data-jpa spring-boot
当我们使用spring boot和spring数据时,如何访问存储库中的实体管理器?
否则,我需要将我的大查询放在注释中,我宁愿有一些清楚的东西......然后是长文本.
Nit*_*ora 17
您将定义一个CustomRepository
来处理此类方案.考虑一下你CustomerRepository
扩展了默认的spring数据JPA接口JPARepository<Customer,Long>
CustomCustomerRepository
使用自定义方法签名创建新接口.
public interface CustomCustomerRepository {
public void customMethod();
}
Run Code Online (Sandbox Code Playgroud)
CustomerRepository
使用扩展接口CustomCustomerRepository
public interface CustomerRepository extends JpaRepository<Customer, Long>, CustomCustomerRepository{
}
Run Code Online (Sandbox Code Playgroud)
创建一个名为CustomerRepositoryImpl
implements 的实现类CustomerRepository
.在这里你可以注入EntityManager
使用@PersistentContext
.命名约定在这里很重要.
public class CustomerRepositoryImpl implements CustomCustomerRepository {
@PersistenceContext
private EntityManager em;
@Override
public void customMethod() {
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
21688 次 |
最近记录: |