如何避免JPA信息库的大量重复代码?

时间:2019-01-14 21:17:07

标签: spring spring-data-jpa jhipster

在我的jHipster项目中,有很多表,并且为每个表创建一个存储库接口。我需要实施多租户, 因此,我将添加几种方法,其中一种参数是这样的departmentId:

@Repository
public interface ClientRepository extends JpaRepository<Client, Long>, JpaSpecificationExecutor<Client> {

    @Query( value = "select * from client c  where department_id in (select id  from department where path like %?1%)" ,nativeQuery = true)
    Page<Client> findAllBydepartmentId(@Param("departmentId") String departmentId, Pageable pageable) ;

    @Query( value = "select * from client c  where client_id = ?2 and department_id in (select id  from department where path like %?1%)" ,nativeQuery = true)
    Page<Client> findAllBydepartmentId(@Param("departmentId") String departmentId, @Param("clientId"), Pageable pageable);

    @Query( value = "delete  from client c  where client_id = ?2 and department_id in (select id  from department where path like %?1%)" ,nativeQuery = true)
    Page<Client> findAllBydepartmentId(@Param("departmentId") String departmentId, @Param("clientId"), Pageable pageable);

我必须对每个实体执行此操作,那么如何避免编写大量重复的代码?

0 个答案:

没有答案