小编r.d*_*onz的帖子

自定义查询Spring Data JPA + REST

在我的数据库中,我有一个表"CITA",其中包含以下属性:id,fecha_hora,descripcion,id_empleado,id_cliente.

我有一个Spring JPA存储库:

public interface CitaRepository extends JpaRepository<Cita, Long> {...}
Run Code Online (Sandbox Code Playgroud)

我需要这个查询:

"SELECT id_empleado, count(id) from Cita GROUP BY id_empleado ORDER BY fecha_hora"

我的问题是我不知道应该把它放在哪里给我一些像Map这样的东西

因为它不起作用:

@Query("SELECT id_empleado, count(id) from Cita GROUP BY id_empleado ORDER BY fecha_hora")
  Map<Integer,Integer> estadisticas();
Run Code Online (Sandbox Code Playgroud)

编辑

如果我尝试从我的REST控制器调用estadisticas(),则会出错.

这是我的REST控制器:

@RestController
@RequestMapping("/app")
public class CitaResource {

    private final Logger log = LoggerFactory.getLogger(CitaResource.class);

    @Inject
    private CitaRepository citaRepository;

@RequestMapping(value = "/rest/citas/estadisticas",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public List<CitaDTO> estadisticas() {
    return citaRepository.estadisticas();
}
Run Code Online (Sandbox Code Playgroud)

这是我的JPA存储库: …

rest spring hibernate jpa spring-data-jpa

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

hibernate ×1

jpa ×1

rest ×1

spring ×1

spring-data-jpa ×1