【发布时间】:2018-07-22 06:52:40
【问题描述】:
我有一个看起来像这样的假客户端:
@RequestMapping(method = RequestMethod.POST, value = "/breakdowns/utmMedium", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
List<Breakdown> getUtmMediumBreakdowns(
@RequestBody Record record,
@RequestParam("since") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime since,
@RequestParam("until") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime until,
@RequestParam("timezone") String timezone
);
@RequestMapping(method = RequestMethod.POST, value = "/breakdowns/utmCampaign", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
List<Breakdown> getUtmCampaignBreakdowns(
@RequestBody Record record,
@RequestParam("since") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime since,
@RequestParam("until") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime until,
@RequestParam("timezone") String timezone
);
@RequestMapping(method = RequestMethod.POST, value = "/breakdowns/utmSource", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
List<Breakdown> getUtmSourceBreakdowns(
@RequestBody Record record,
@RequestParam("since") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime since,
@RequestParam("until") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) ZonedDateTime until,
@RequestParam("timezone") String timezone
);
如您所见,除了 API 路径根据参数 utmMedium、utmCampaign 和 utmSource 更改之外,这三种方法完全相同,因为在服务器端我们确实对它们进行了不同的处理.
我无法更改服务器,因此无法更改端点以接受此参数作为请求参数或其他内容。 我想知道是否有办法让我仍然参数化这部分路径,所以我只有一个方法而不是三个。
【问题讨论】:
标签: java rest spring-cloud-feign