Swagger中paramType

Swagger中paramType
paramType:表示参数放在哪个地方
header–>请求参数的获取:@RequestHeader(代码中接收注解)
query–>请求参数的获取:@RequestParam(代码中接收注解)
path(用于restful接口)–>请求参数的获取:@PathVariable(代码中接收注解)
body–>请求参数的获取:@RequestBody(代码中接收注解)
form(不常用)

demo_query:

	@GetMapping("getList")
    @ApiOperation("列表查询接口")
    @ApiImplicitParams({
     
            @ApiImplicitParam(name = "current", value = "当前页码,默认1", example = "1",
                    paramType = "query", dataType = "int", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数,默认10", example = "10",
                    paramType = "query", dataType = "int", required = false)
    })
    public Result<List<QueryListVO>> getList(
            @RequestParam(value = "current", required = false, defaultValue = PageConstant.PAGE_CURRENT + "")Integer current,
            @RequestParam(value = "pageSize", required = false, defaultValue = PageConstant.PAGE_SIZE + "")Integer pageSize) {
     
}

Swagger中paramType_第1张图片

demo_path:

@GetMapping("delete/{id}")
    @ApiOperation("删除接口")
    @ApiImplicitParams({
     
            @ApiImplicitParam(name = "id", value = "id",
                    example = "10086", paramType = "path", required = true, dataType = "long")
    })
    public Result delete(@PathVariable("id") Long id) {
     
}

Swagger中paramType_第2张图片

demo_form:

 @PostMapping(value = "add", headers = "content-type=multipart/form-data")
    @ApiOperation("附件保存接口(多文件上传不支持swagger测试)")
    @ApiImplicitParams({
     
            @ApiImplicitParam(name = "id", value = "*id", example = "10086", paramType = "form", required = true),
            @ApiImplicitParam(name = "status", value = "附件状态", example = "3",
                    paramType = "form", allowableValues = "2,3", required = true)
    })
    public Result add(AddDTO addDTO,
                      @ApiParam(value = "*附件") @RequestParam(value = "materialSigns", required = false)
                              MultipartFile[] file,
                     ) {
     

Swagger中paramType_第3张图片
设置addDTO不在文档中生成

.ignoredParameterTypes(AddDTO.class)

@Bean
    public Docket createRestApi() {
     
        List<ResponseMessage> responseMessageList = new ArrayList<>();
        responseMessageList.add(new ResponseMessageBuilder().code(401).message("未经授权")
                .responseModel(new ModelRef("Result")).build());
        responseMessageList.add(new ResponseMessageBuilder().code(404).message("找不到资源")
                .responseModel(new ModelRef("Result")).build());
        responseMessageList.add(new ResponseMessageBuilder().code(500).message("服务器内部错误")
                .responseModel(new ModelRef("Result")).build());

        return new Docket(DocumentationType.SWAGGER_2)
                .globalResponseMessage(RequestMethod.GET, responseMessageList)
                .globalResponseMessage(RequestMethod.POST, responseMessageList)
                .globalResponseMessage(RequestMethod.PUT, responseMessageList)
                .globalResponseMessage(RequestMethod.DELETE, responseMessageList)
                .apiInfo(apiInfo())
                .ignoredParameterTypes(AddDTO.class)//不生成文档的类
                .select()                       //按条件指定生成文档接口
                .paths(PathSelectors.any())
                .build();
    }

你可能感兴趣的:(swagger)