Spring Data REST custom query integration

前端 未结 3 1009
礼貌的吻别
礼貌的吻别 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 19:59

    Spring HATEOAS has changed the name of Resource, PagedResources and some other classes. See here. Below is a working version in 2020.

    @RepositoryRestController
    public class EmployeeSearchController {
        @Autowired
        private EmployeeRepository employeRepository;
    
        @Autowired
        private PagedResourcesAssembler pagedAssembler;
    
        @RequestMapping(value = "/employees/search/all", method = RequestMethod.GET)
        public ResponseEntity>> getEmployees(PersistentEntityResourceAssembler entityAssembler,,
                                                                              EmployeeCriteria filterCriteria,
                                                                              Pageable pageable) {
    
            Specification specification = new EmployeeSpecification(filterCriteria);
    
            Page employees = employeeRepository.findAll(specification, pageable);
            return ResponseEntity.ok(pagedAssembler.toModel(plants, (RepresentationModelAssembler) entityAssembler));
        }
    }
    

提交回复
热议问题