SpringBoot集成Swagger2

參考文檔:http://blog.csdn.net/xupeng874395012/article/details/68946676html

1.Swagger與啓動類保持一致api

 

2.註解說明ide

 

3.訪問地址:http://localhost:8080/swagger-ui.htmlui

 

注意:.net

因爲Swagger1與Swagge2有區別。在1中@ApiRespone的code能夠隨便設置,2不行,2只能根據Http狀態嗎設置,不然啓動會報以下錯誤rest

 

參數類型code

  1. paramType:參數位置
  • header 對應註解:@RequestHeader
  • query 對應註解:@RequestParam
  • path  對應註解: @PathVariable
  • body 對應註解: @RequestBody

設置中文htm

 

標識Swagger接口對象

@Api(value = "api", description = "收貨地址Controller" )blog

 

返回對象註解

 

顯示對應請求的對應請求方式,必須指定rest的提交方式

 

文件上傳

 

後續:

嘗試設置是否能夠驗證訪問

@Configuration

public class WebConfig extends WebMvcConfigurerAdapter {

 

 

    @Override

    public void addInterceptors(InterceptorRegistry registry) {

       registry.addInterceptor(new TokenInterceptor(tokenManager))

               .addPathPatterns("/**").excludePathPatterns("/configuration/ui", "/configuration/security", "/v2/api-docs", "/swagger**");

    }

 }

相關文章
相關標籤/搜索