资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

springcloud(五):Swagger2的集成-创新互联

1、概念

创新互联公司专注于龙胜企业网站建设,响应式网站,商城网站建设。龙胜网站建设公司,为龙胜等地区提供建站服务。全流程定制网站制作,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

  Swagger2 – 服务接口文档,用来前端与后端联系,提高之间的沟通,更有效率的完成项目之间的联调。

2、集成

 2.1 、通过pom文件导入swagger

           

             swagger-springmvc

             swagger-springmvc

            

 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 createSoftsimBinding(@RequestBody SoftsimBindingCreateReq req)

         {

       }

4、导入swagger相关的ui到项目里面,可以建static文件夹存放swagger的ui文件

5、通过地址http://localhost:8020/swagger/index.html访问

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享题目:springcloud(五):Swagger2的集成-创新互联
网站地址:http://cdkjz.cn/article/dhsjcs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220