Spring Data REST custom query integration

前端 未结 3 999
礼貌的吻别
礼貌的吻别 2020-12-07 19:14

I want to create a REST link for an Employee entity that will basically be a findByAllFields query. Of course this should be combined with Pa

3条回答
  •  春和景丽
    2020-12-07 20:03

    The code by @Stackee007 works but the resource won't include self links. In order to do that, a little more is required.

    @Autowired
    PagedResourcesAssembler pagedResourcesAssembler;
    
    @RequestMapping(value = "/findTodaysSchedule")
    public HttpEntity>> getTodaysSchedule(
            PersistentEntityResourceAssembler entityAssembler, Pageable pageable) {
        Page todaysSchedule = apptRepo.findByStartTimeBetween(beginningOfDay, endOfDay, pageable);
    
        @SuppressWarnings({ "unchecked", "rawtypes" })
        PagedResources> resource = pagedResourcesAssembler.toResource(todaysSchedule,
                    (ResourceAssembler) entityAssembler);
    
        return new ResponseEntity<>(resource, HttpStatus.OK);
    }
    

提交回复
热议问题