how to configure spring-data-rest search method path with @PathVariable

前端 未结 2 1383
遇见更好的自我
遇见更好的自我 2021-01-15 22:18

I want to customize my spring-data-rest search method path by passing parameter as a path variable like follows

http://localhost:8080/orders/search/customers         


        
2条回答
  •  甜味超标
    2021-01-15 22:47

    You can use custom handler similar to this:

    @RepositoryRestController
    public class OrderController {
    
        @Autowired
        OrderRepository orderRepository;
    
        @GetMapping("/orders/search/customers/{id}")
        public @ResponseBody ResponseEntity getByCustomers(@PathVariable Integer customer) {
            Order order = orderRepository.findOne(id);
            if(order == null) return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            Resource resource = new Resource(order); 
            return ResponseEntity.ok(resource);
        }
    }
    

    More about this can be found here.

提交回复
热议问题