问题出现,最近在学QueryDSL时,起初搭好环境后,启动i项目一直报错,No property findOffEmpCust found for type CustomersEntity!

代码示例

@Repository
public interface CustomerRepo extends JpaRepository<CustomersEntity,Long>, JpaSpecificationExecutor<CustomersEntity>, CustomerRepoCustom {
}
public interface CustomerRepoCustom {

    // 自定义返回
    public List<OffEmpCustVo> findOffEmpCust();

}

public class CustomerRepoCustomImpl implements CustomerRepoCustom {

@PersistenceContext
private EntityManager em;

@Override
public List<OffEmpCustVo> findOffEmpCust() {
    JPAQuery<OffEmpCustVo> query = new JPAQuery<>(em);

    QCustomersEntity customers = QCustomersEntity.customersEntity;
    QOfficesEntity office = QOfficesEntity.officesEntity;
    QEmployeesEntity employee = QEmployeesEntity.employeesEntity;

    List<Tuple> list = query.select(
            office.officeCode,
            office.country.as("offCountry"),
            office.state.as("offState"),
            employee.employeeNumber.as("emploNumber"),
            employee.email.as("emploEmail"),
            customers.customerNumber.as("custNumber"),
            customers.state.as("custState")).from(office).leftJoin(employee).on(office.officeCode.eq(employee.officeCode)).leftJoin(customers).on(employee.employeeNumber.eq(customers.salesRepEmployeeNumber)).fetchResults().getResults();

    List<OffEmpCustVo> voList = list.stream().map(r -> JSONUtil.toBean(JSONUtil.toJsonStr(r), OffEmpCustVo.class)).collect(Collectors.toList());

    return voList;

    // select off.officeCode , off.country, off.state , em.employeeNumber, em.email, cu.customerNumber , cu.state  from offices off left outer join employees em on (off.officeCode=em.officeCode) left outer join customers cu on (em.employeeNumber=cu.salesRepEmployeeNumber)
}

}

注意:上图是改后的目录结构,之前我的命名不是这样的,才会出错,总结一下,当需要自定义存储库,一定要和本身的存储库,名称一定要对应,还有自定义存储库的实现类命名一定要规范以Impl后缀,前以自定义存储库的名称前缀。