首页 文章

使用带有swagger ui的@RequestParam注释方法

提问于
浏览
20

我正在使用 Springfox 库生成REST服务的文档,并在Swagger UI中显示它 . 我按照Springfox documentation的指示行事 .

我有一个控制器,它使用查询字符串中的参数,方法映射如下:

@ApiOperation(value = "")
@RequestMapping(method = GET, value = "/customcollection/{id}/data")
public Iterable<CustomeType> getData(@ApiParam(value = "The identifier of the time series.") 
    @PathVariable String id,
    @ApiParam(name = "startDate", value = "start date", defaultValue = "")
    @RequestParam("startDate") String startDate,
    @ApiParam(name = "endDate", value = "end date", defaultValue = "")
    @RequestParam("endDate") String endDate)

swagger-ui中生成的映射器显示为:

GET /customcollection/{id}/data{?startDate,endDate}

参数在UI中正确显示:
enter image description here

但是当我点击Try it Out时,请求URL会被误认为:

http://localhost:8080/customcollection/1/data {?startDate,endDate}?startDate = 1&endDate = 2

怎么修好?

1 回答

  • 20

    这是由线路造成的

    enableUrlTemplating(true)
    

    Docket 配置中,我从示例中复制并忘记删除 .

    删除此行后,一切都按预期工作 .

相关问题