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

使用SpringMVC怎么對(duì)Swagger進(jìn)行整合-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)使用SpringMVC怎么對(duì)Swagger進(jìn)行整合,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

創(chuàng)新互聯(lián)成立于2013年,先為即墨等服務(wù)建站,即墨等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢(xún)服務(wù)。為即墨企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

配置

1、引入相關(guān)jar包:

<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>

2、創(chuàng)建java配置類(lèi)

@Configuration
@EnableSwagger2
public class Swagger2 {
  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
         // 文檔標(biāo)題
        .title("wish")
        // 文檔描述
        .description("https://github.com/handexing").termsOfServiceUrl("https://github.com/handexing")
        .version("v1")
        .build();
  }
  @Bean
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .select()
        // 指定controller存放的目錄路徑
        .apis(RequestHandlerSelectors.basePackage("com.wish.controller"))
        .paths(PathSelectors.any())
        .build();
  }
}

3、編寫(xiě)接口文檔測(cè)試

@RequestMapping(value = "testSawgger", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@ApiOperation(value = "測(cè)試swagger", httpMethod = "POST", notes = "testSawgger")
public ExecuteResult<Boolean> addUser(@ApiParam(value = "參數(shù)", required = true) Long id) {
  ExecuteResult<Boolean> result = new ExecuteResult<Boolean>();
  try {
    result.setSuccess(true);
  } catch (Exception e) {
    result.setSuccess(false);
  }
  return result;
}

說(shuō)明:

@ApiOperation:用在方法之上

1、value: 表示接口名稱(chēng)

2、notes: 表示接口詳細(xì)描述

3、httpMethod:表示接口請(qǐng)求方法類(lèi)型

@ApiParam:用在方法參數(shù)上

1、required:表示參數(shù)是否必須傳

2、name:表示參數(shù)名稱(chēng)

3、value:表示參數(shù)描述

關(guān)于使用SpringMVC怎么對(duì)Swagger進(jìn)行整合就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

網(wǎng)頁(yè)題目:使用SpringMVC怎么對(duì)Swagger進(jìn)行整合-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://chinadenli.net/article12/hgpdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)自適應(yīng)網(wǎng)站網(wǎng)站改版軟件開(kāi)發(fā)網(wǎng)站設(shè)計(jì)面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(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)

微信小程序開(kāi)發(fā)