溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

spring cloud(五):Swagger2的集成

發布時間:2020-07-14 12:00:46 來源:網絡 閱讀:3851 作者:browser123 欄目:軟件技術

1、概念

   Swagger2 – 服務接口文檔,用來前端與后端聯系,提高之間的溝通,更有效率的完成項目之間的聯調。

2、集成

  2.1 、通過pom文件導入swagger

           <dependency>

             <groupId>swagger-springmvc</groupId>

             <artifactId>swagger-springmvc</artifactId>

             </dependency>

 2.2、建立swagger模塊,編寫模塊類

         @Configuration

        @EnableWebMvc

        @EnableSwagger

        @ComponentScan(basePackages={"com.sz.xx"})

        public class ApiSwaggerConfig extends WebMvcConfigurerAdapter{

        private SpringSwaggerConfig springSwaggerConfig;

          @Autowired

          public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig)

          {

            this.springSwaggerConfig = springSwaggerConfig;

          }

          @Bean

          public SwaggerSpringMvcPlugin customImplementation()

          {

            return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(apiInfo()).includePatterns(new String[] { "/xx/.*?" })

              .apiVersion("0.0.1")

              .swaggerGroup("api");

          }

          private ApiInfo apiInfo() {

            ApiInfo apiInfo = new ApiInfo("XX API接口文檔", "API-DOC", "", "test@163.com", "My License", "My Apps API License URL");

            return apiInfo;

          }

          public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer)

          {

            configurer.enable();

          }

          class GtPaths extends SwaggerPathProvider {

            GtPaths() {

            }

            protected String applicationPath() {

              return "/restapi";

            }

            protected String getDocumentationPath()

            {

              return "/restapi";

            }

          }

        }

         }

       

3、代碼里面使用swagger

        3.1、UserContoller

        @Api(value="userApi", description="user管理接口", position=1)

        @Controller

        @ApiService

       public class   UserContoller{

         @ApiOperation(notes="新增用戶接口", value="新增用戶(開發責任人:xx)")

          @ApiServiceOperation("新增用戶接口")

            @RequestMapping(value={"/xx/user/add"}, method={RequestMethod.POST})

          @ResponseBody

          public Response<Integer> createSoftsimBinding(@RequestBody SoftsimBindingCreateReq req)

          {

         }

4、導入swagger相關的ui到項目里面,可以建static文件夾存放swagger的ui文件


5、通過地址http://localhost:8020/swagger/index.html訪問

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女