欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Swagger接口說明文檔的配置和使用方法

這篇文章主要講解了“Swagger接口說明文檔的配置和使用方法”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Swagger接口說明文檔的配置和使用方法”吧!

目前創(chuàng)新互聯(lián)已為近1000家的企業(yè)提供了網站建設、域名、虛擬主機網站托管運營、企業(yè)網站設計、梨樹網站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

Swagger是一個開源的接口配置文檔,一般用于前后端分離,代替后端人員為前端人員書寫繁瑣的接口文檔,使后端人員從繁瑣的接口文檔中解脫出來。Swagger如何使用呢?首先我們要在springboot中的pom文件引入依賴包

<!-- swagger依賴組件 -->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.7.0</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>2.7.0</version>
            </dependency>

其次,添加swagger的配置文件,該配置文件定義了網頁訪問swagger2的路徑以及標題,描述等信息

package com.xash.quartzDemo.config;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configurable
public class SwaggerConfig{
	   @Bean
	    public Docket api(){
	        return new Docket(DocumentationType.SWAGGER_2)
	        		.groupName("測試模塊")
	                .apiInfo(getApiInfo())
	                .select()
	                .apis(RequestHandlerSelectors.basePackage("com.xash.quartzDemo.controller"))
	                .paths(PathSelectors.regex(".*/.*"))
	                .build();
	    }

	    private ApiInfo getApiInfo(){
	    	
	        return new ApiInfoBuilder()
	                .title("測試模塊")
	                .description("小標題")
	                .version("1.0")
	                .build();
	    }
	    @Bean
	    public Docket api1(){
	        return new Docket(DocumentationType.SWAGGER_2)
	        		.groupName("測試模塊1")
	                .apiInfo(getApiInfo1())
	                .select()
	                .apis(RequestHandlerSelectors.basePackage("com.xash.quartzDemo.controller"))
	                .paths(PathSelectors.regex(".*/.*"))
	                .build();
	    }
	    @Bean
	    private ApiInfo getApiInfo1(){
	        return new ApiInfoBuilder()
	                .title("測試模塊1")
	                .description("小標題")
	                .version("1.0")
	                .build();
	    }


}

這樣,我們就可以在要添加接口文檔的地方利用注解添加相應的接口文檔信息了

例如:

@Api(tags="這是個測試Controller")
public class PermissionController {}類上加注解,說明該類具有的功能

  @ApiOperation(value = "根據用戶id查詢權限")
     public String selectPermissionById(ModelMap map,@ApiParam("id") @RequestParam("id")int id){
         System.out.println("開始查詢");
         map.put("name", "歡飲使用thymeleaf模板引擎");
         map.put("sysPermission", permissionService.selectPermissionById(id));
         return "index";
     }方法上加注解,表示方法的功能,以及可見在形參上加注解,指定形參,對形參進行描述

訪問地址默認為192.168.2.199:8080/項目應用/swagger2-ui.html

感謝各位的閱讀,以上就是“Swagger接口說明文檔的配置和使用方法”的內容了,經過本文的學習后,相信大家對Swagger接口說明文檔的配置和使用方法這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關知識點的文章,歡迎關注!

本文名稱:Swagger接口說明文檔的配置和使用方法
本文鏈接:http://chinadenli.net/article26/ppcjcg.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網站網站制作網站收錄App設計電子商務App開發(fā)

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網站網頁設計