如下使用投影如何?
static interface VehicleStats { public String getSourceModule(); public Long getVehicleCount();}你的存储库方法是
@Query("select v.sourceModule as sourceModule, count(v) as vehicleCount from Vehicle v group by v.sourceModule")List<VehicleStats> sourceModuleStats();在Service类中,可以使用以下接口方法。
List<VehicleStats> objects = vehicleRepository.sourceModuleStats();return objects.stream() .map(o->SourceModuleStatDTO.from(getSourceModule(),getVehicleCount() ) .collect(Collectors.toList());



