成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

如何實(shí)現(xiàn)knife4j導(dǎo)出離線接口文檔

本篇內(nèi)容主要講解“如何實(shí)現(xiàn)knife4j導(dǎo)出離線接口文檔”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“如何實(shí)現(xiàn)knife4j導(dǎo)出離線接口文檔”吧!

為錫林郭勒盟等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及錫林郭勒盟網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、錫林郭勒盟網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!

** 導(dǎo)出離線接口文檔,媽媽再也不用讓我手動(dòng)寫(xiě)接口文檔了 **

  1. 1 引入依賴

 <dependency> 
<groupId>io.springfox</groupId> 
<artifactId>springfox-boot-starter</artifactId> 
<version>3.0.0</version> 
</dependency>
    <!-- https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-spring-boot-starter -->
    <dependency>
        <groupId>com.github.xiaoymin</groupId>
        <artifactId>knife4j-spring-boot-starter</artifactId>
        <version>3.0.2</version>
    </dependency>`
  1. 2 增加swagger配置類

package com.example.demo.conf;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.*;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * swagger 配置
 *
 * @author xmtx
 */
@Configuration
@EnableOpenApi
@EnableKnife4j
public class Swagger3Config {

    @Bean
    public Docket systemApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("小明童鞋demo")
                .genericModelSubstitutes(DeferredResult.class).useDefaultResponseMessages(false).forCodeGeneration(true)
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                // 這里寫(xiě)controller 所在的路徑
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.any()).build()
                .pathMapping("/")
                // 暫時(shí)不加權(quán)限認(rèn)證
//                .securitySchemes(Collections.singletonList(securitySchema()))
//                .securityContexts(Collections.singletonList(securityContext()))
                .apiInfo(systemApiInfo());
    }

    private ApiInfo systemApiInfo() {
        return new ApiInfoBuilder()
                .title("小明童鞋demo")
                .description("測(cè)試swagger整合knife4j生成離線接口文檔")
                .termsOfServiceUrl("https://my.oschina.net/xiaomingnevermind")
                .contact(new Contact("xmtx", "", "xmtx.2015@gmail.com"))
                .version("1.0")
                .build();
    }

    /**
     * 生成全局通用參數(shù)
     *
     * @return
     */

    private List<RequestParameter> getGlobalRequestParameters() {
        List<RequestParameter> parameters = new ArrayList<>();
        parameters.add(new RequestParameterBuilder()
                .name("x-access-token")
                .description("令牌")
                .required(false)
                .in(ParameterType.HEADER)
                .build());
        parameters.add(new RequestParameterBuilder()
                .name("Equipment-Type")
                .description("產(chǎn)品類型")
                .required(false)
                .in(ParameterType.HEADER)
                .build());
        return parameters;
    }

    /**
     * 生成通用響應(yīng)信息
     *
     * @return
     */
    private List<Response> getGlobalResponseMessage() {
        List<Response> responseList = new ArrayList<>();
        responseList.add(new ResponseBuilder().code("404").description("找不到資源").build());
        return responseList;
    }

//
//    private OAuth securitySchema() {
//
//        List<AuthorizationScope> authorizationScopeList = new ArrayList();
//        List<GrantType> grantTypes = new ArrayList();
//        GrantType creGrant = new ResourceOwnerPasswordCredentialsGrant("/oauth/token");
//
//        grantTypes.add(creGrant);
//
//        return new OAuth("oauth3schema", authorizationScopeList, grantTypes);
//
//    }

//
//    private SecurityContext securityContext() {
//        return SecurityContext.builder()
//                .securityReferences(defaultAuth())
//                .forPaths(PathSelectors.ant("/v1/api/**"))
//                .build();
//    }

    private List<SecurityReference> defaultAuth() {

        final AuthorizationScope[] authorizationScopes = new AuthorizationScope[0];
        return Collections.singletonList(new SecurityReference("oauth3schema", authorizationScopes));
    }
}

1. 3. 編寫(xiě)一個(gè)controller進(jìn)行測(cè)試

private static final Logger log = LoggerFactory.getLogger(AspectController.class);

@Autowired
private AspectService aspectService;

@ApiOperation(value = "測(cè)試getaspect")
@GetMapping(value = "/getaspect")
public String getAspect(@ApiParam("名稱") String name,
                        @ApiParam Integer age) throws InterruptedException {
    AspectBean aspectBean = new AspectBean();
    aspectBean.setAge(age);
    aspectBean.setBirthday(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date().getTime()));
    aspectBean.setSex(1);
    aspectBean.setName(name);
    return JSON.toJSONString(aspectService.testAspect(aspectBean));
}

@PostMapping(value = "/postaspect")
public String postAspect(@RequestBody AspectBean aspectBean) throws InterruptedException {
    return JSON.toJSONString(aspectService.testAspect(aspectBean));
}

@GetMapping(value = "/init")
public boolean init() {
    return aspectService.init();
}

1. 4. 查看效果圖

如何實(shí)現(xiàn)knife4j導(dǎo)出離線接口文檔

如何實(shí)現(xiàn)knife4j導(dǎo)出離線接口文檔

如何實(shí)現(xiàn)knife4j導(dǎo)出離線接口文檔

如何實(shí)現(xiàn)knife4j導(dǎo)出離線接口文檔

到此,相信大家對(duì)“如何實(shí)現(xiàn)knife4j導(dǎo)出離線接口文檔”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

網(wǎng)站題目:如何實(shí)現(xiàn)knife4j導(dǎo)出離線接口文檔
當(dāng)前地址:http://jinyejixie.com/article32/ggessc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、網(wǎng)站建設(shè)、面包屑導(dǎo)航搜索引擎優(yōu)化

廣告

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

h5響應(yīng)式網(wǎng)站建設(shè)
中江县| 嘉定区| 沙坪坝区| 沛县| 武定县| 福鼎市| 安泽县| 新安县| 高淳县| 门头沟区| 烟台市| 海林市| 连云港市| 民权县| 连云港市| 江源县| 西安市| 吕梁市| 简阳市| 南京市| 栖霞市| 关岭| 龙川县| 象山县| 泰顺县| 分宜县| 廉江市| 德江县| 太白县| 松潘县| 静宁县| 库车县| 甘孜县| 石屏县| 宜都市| 南漳县| 涞源县| 马边| 彝良县| 九江县| 南昌县|