如何使用@PathVariable 配置 spring-data-rest 搜索方法路径 [英] how to configure spring-data-rest search method path with @PathVariable
本文介绍了如何使用@PathVariable 配置 spring-data-rest 搜索方法路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过将参数作为路径变量传递来自定义我的 spring-data-rest 搜索方法路径,如下所示
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/{customerId}
findByCustomer(@PathVariable("customerId") Integer customer);
搜索资源列表如下
http://localhost:8080/orders/search/customers/%7BcustomerId%7D
如何使用路径参数公开搜索网址?
How to expose search url with path params?
推荐答案
您可以使用类似这样的自定义处理程序:
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<Order> resource = new Resource<Order>(order);
return ResponseEntity.ok(resource);
}
}
可以在 这里.
这篇关于如何使用@PathVariable 配置 spring-data-rest 搜索方法路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文