我想通过将参数作为路径变量传递来定制我的spring-data-rest搜索方法路径,如下所示
http://localhost:8080/orders/search/customers/{customerId}
findByCustomer(@PathVariable("customerId") Integer customer);搜索资源按如下方式列出链接
http://localhost:8080/orders/search/customers/%7BcustomerId%7D如何使用路径参数公开搜索url?
发布于 2016-10-05 18:05:21
您可以使用如下所示的自定义处理程序:
@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);
}
}有关这方面的更多信息,请访问here。
发布于 2016-10-05 15:07:09
使用HttpServletRequest获取请求url:
findByCustomer(@PathVariable("customerId") Integer customer, HttpServletRequest request){
String request = request.getRequestURL().toString(); // StringBuffer, so use append if you want to...
[...]
}您也可以在?之后使用request.getQueryString()获取查询部分。
https://stackoverflow.com/questions/39866926
复制相似问题