java - RestTemplate Swagger 没有足够的变量值可扩展
问题描述
我的方法抛出异常:
@GetMapping(value = "/orders/{email}")
private List<Order> ordersByEmail(@PathVariable String email) {
List<Order> list = restTemplate.exchange(
"http://localhost:8082/api/v1/orders/email/{email}",
HttpMethod.GET,
new HttpEntity<>(email),
new ParameterizedTypeReference<List<Order>>() {
}).getBody();
}
请求url方法:
@ApiOperation("Find orders by email")
@GetMapping(value = "/email/{email}")
public List<Order> findOrdersByEmail(@PathVariable String email) {
return orderService.findByEmail(email);
}
卷曲:
curl -X GET "http://localhost:8084/api/v1/processor/orders/{email}?email=string" -H "accept: */*"
请求网址:
http://localhost:8084/api/v1/processor/orders/{email}?email=string
大摇大摆的回应:
Error:
Response body
Download
{
"timestamp": "2019-01-04T00:27:34.059+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Not enough variable values available to expand 'email'",
"path": "/api/v1/processor/orders/%7Bemail%7D"
}
Response headers
connection: close
content-type: application/json;charset=UTF-8
date: Fri, 04 Jan 2019 00:27:34 GMT
transfer-encoding: chunked
解决方案
您的问题与 {email} 有关。
@GetMapping(value = "/orders/{email}")
private List<Order> ordersByEmail(@PathVariable String email) {
通过指定 {email} 和 PathVariable,这意味着您的控制器将在 /orders/ 之后获取变量并将其分配给电子邮件。
尝试http://localhost:8084/api/v1/processor/orders/string
,curl -X GET "http://localhost:8084/api/v1/processor/orders/string" -H "accept: /"
而不是。您无需在网址中明确输入 {email}
推荐阅读
- php - 如何展平和输出两个多维数组并打印成对值的组合?
- python - Python 3.8.2 中的时间格式化
- javascript - 用于创建类似 Kibana 的搜索栏的 JavaScript 包
- vue.js - Vue Chart JS 和选项反应性
- ios - 用不同的字体大小对齐 UIButton 和 UILabel 文本
- java - 当我尝试 git push heroku 时出现错误
- javascript - 我可以为视频流创建 K6 负载测试吗
- linux - iraf, make: *** 没有规则使目标'sptable'。停止
- regex - 无法以正确的方式从某些 json 响应中解析出所有容器中的两个字段
- database - 查询没有主键的 Firestore