Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Spring boot中为swagger UI指定请求主体?_Java_Spring Boot_Swagger - Fatal编程技术网

Java 如何在Spring boot中为swagger UI指定请求主体?

Java 如何在Spring boot中为swagger UI指定请求主体?,java,spring-boot,swagger,Java,Spring Boot,Swagger,我有以下带注释的控制器用于招摇过市: @PostMapping("/getMediaDataProduct/V2") @ResponseBody @ApiOperation(value = "get media data product v2") @ApiResponses({@ApiResponse(code = 200, message = "Successful", response = MediaDa

我有以下带注释的控制器用于招摇过市:

  @PostMapping("/getMediaDataProduct/V2")
    @ResponseBody
    @ApiOperation(value = "get media data product v2")
    @ApiResponses({@ApiResponse(code = 200, message = "Successful", response = MediaDataProductResponseV2.class)})

    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "xxxxx", value = "xxxx", paramType = "header", required = true),
            @ApiImplicitParam(name = "xxxx", value = "xxxx", paramType = "header", required = true),
            @ApiImplicitParam(name = "xxxx", value = "xxxx", paramType = "header"),
            @ApiImplicitParam(name = "xxxx", value = "xxxx", paramType = "header", required = true),
            //  @ApiImplicitParam(name = "xxxxxx", value = "xxx", paramType = "header" ,required = true),
            @ApiImplicitParam(name = "xxxxxx", value = "xxxxx", paramType = "header"),
            @ApiImplicitParam(name = "xxxxxxx", value = "xxxxxxxx", paramType = "header", required = true)})

    public ResponseEntity getMediaDataProductV2(@RequestBody final String request, @RequestHeader final HttpHeaders headers) {
        Slogger.get().debug("/getMediaDataProduct/V2: this.mediaDataService: " + this.mediaDataService);

        MediaDataProductResponseV2 response = mediaDataService.getMediaDataProductV2(request);
        HttpStatus status = getHttpStatus(response.getStatusMessages(), response.getSystemErrors());
        List<StatusMessage> statusMessages = appendSuccessStatusMessage(response.getStatusMessages(), status);
        if(statusMessages !=null) {
            response.setStatusMessages(statusMessages);
        }
        return new ResponseEntity<>(response, new HttpHeaders(), status);
    }
@PostMapping(/getMediaDataProduct/V2)
@应答器
@ApiOperation(value=“获取媒体数据产品v2”)
@ApiResponses({@ApiResponse(code=200,message=“Successful”,response=MediaDataProductResponseV2.class)})
@APIMPLITParams(值={
@apimplicitparam(name=“xxxxx”,value=“xxxx”,paramType=“header”,required=true),
@apimplicitparam(name=“xxxx”,value=“xxxx”,paramType=“header”,required=true),
@apimplicitparam(name=“xxxx”,value=“xxxx”,paramType=“header”),
@apimplicitparam(name=“xxxx”,value=“xxxx”,paramType=“header”,required=true),
//@apimplicitparam(name=“xxxxxx”,value=“xxx”,paramType=“header”,required=true),
@apimplicitparam(name=“xxxxxx”,value=“xxxxx”,paramType=“header”),
@apimplicitparam(name=“xxxxxxx”,value=“xxxxxxx”,paramType=“header”,required=true)})
公共响应属性getMediaDataProductV2(@RequestBody final String request,@RequestHeader final HttpHeaders){
Slogger.get().debug(“/getMediaDataProduct/V2:this.mediaDataService:“+this.mediaDataService”);
MediaDataProductResponseV2 response=mediaDataService.getMediaDataProductV2(请求);
HttpStatus status=getHttpStatus(response.getStatusMessages(),response.getSystemErrors());
List statusMessages=appendSuccessStatusMessage(response.getStatusMessages(),status);
if(statusMessages!=null){
response.setStatusMessages(状态消息);
}
返回新的ResponseEntity(响应,新的HttpHeaders(),状态);
}
如何指定请求主体,使其显示在swagger UI中


更新:我曾在许多论坛上对此进行过研究,但似乎没有找到答案。“如何像我处理ApiResponses一样,使用swagger注释来指定请求主体类?”。在为body创建的swagger UI中有一个默认参数,但不知道如何通过引用request body类来指定它。

如果我正确理解了您的问题,您需要在swagger定义中显示一个响应类型。大多数情况下,Swagger会自动将您的方法返回类型映射为响应类型

但是,当它是一个泛型类时,它不能这样做,就像您的例子一样,它的
ResponseEntity

如果您可以将返回类型设置为类似于
ResponseEntity
,它应该可以工作。

请先分享您的观察结果。有很多博客和论坛解释招摇文档。请说明您的设置中到底出了什么问题?