最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot基于Swagger2構(gòu)建API文檔過程解析

 更新時(shí)間:2019年11月06日 08:33:48   作者:我好難啊upup  
這篇文章主要介紹了SpringBoot基于Swagger2構(gòu)建API文檔過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

一、添加依賴

<!--SpringBoot使用Swagger2構(gòu)建API文檔的依賴-->
    <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>

二、創(chuàng)建Swagger2配置類

package com.offcn.config;

import org.springframework.context.annotation.Configuration;
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;

@Configuration//表示該類為一個(gè)配置類,相當(dāng)于spring中的xml配置文件
@EnableSwagger2 //開啟在線文檔
public class SwaggerConfig {

  //1.聲明 api 文檔的屬性
  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        .title("Spring Boot中使用Swagger2構(gòu)建RESTful APIs")
        .description("優(yōu)就業(yè)")
        .termsOfServiceUrl("http://www.ujiuye.com/")
        .contact("小劉同學(xué)")
        .version("1.0")
        .build();
  }

  //配置核心配置信息
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.offcn.controller"))
        .paths(PathSelectors.any())
        .build();
  }
}

三、修改Controller 增加文檔注釋

通過@ApiOperation注解來給API增加說明

通過@ApiImplicitParams@ApiImplicitParam注解來給參數(shù)增加說明

package com.offcn.controller;

import com.offcn.dao.UserDao;
import com.offcn.entity.User;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/rest")
@RestController
public class RestFulController {

  @Autowired
  private UserDao userDao;

  @GetMapping("/getUserById")
  @ApiOperation(value="查找指定id用戶信息", notes="根據(jù)id查找用戶信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "用戶ID", required = true, dataType = "Integer"),
  })
  public User getUserById(Integer id){
    User user = userDao.getOne(id);
    return user;
  }

  @DeleteMapping("/del")
  @ApiOperation(value="刪除指定id用戶信息", notes="根據(jù)id刪除用戶信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "用戶ID", required = true, dataType = "Integer"),
  })
  public String delUserById(Integer id){
    userDao.deleteById(id);
    return "success";
  }
}

四、查看Swagger2文檔

重啟項(xiàng)目

訪問:

http://localhost:8080/swagger-ui.html

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot查詢數(shù)據(jù)庫(kù)導(dǎo)出報(bào)表文件方式

    SpringBoot查詢數(shù)據(jù)庫(kù)導(dǎo)出報(bào)表文件方式

    這篇文章主要介紹了SpringBoot查詢數(shù)據(jù)庫(kù)導(dǎo)出報(bào)表文件方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • 在SpringBoot接口中正確地序列化時(shí)間字段的方法

    在SpringBoot接口中正確地序列化時(shí)間字段的方法

    文章主要介紹在 Spring Boot 接口中正確序列化時(shí)間字段的方法,包括 Java 中Date和LocalDateTime類型的區(qū)別,JSON 序列化和請(qǐng)求參數(shù)中時(shí)間字段的處理,如時(shí)間字符串的格式配置、時(shí)間戳的使用及相關(guān)配置,還提到了在 Swagger UI 中的類型設(shè)置,需要的朋友可以參考下
    2024-11-11
  • JDK10新特性之var泛型和多個(gè)接口實(shí)現(xiàn)方法

    JDK10新特性之var泛型和多個(gè)接口實(shí)現(xiàn)方法

    這篇文章主要介紹了JDK10的新特性:var泛型和多個(gè)接口實(shí)現(xiàn)方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-05-05
  • Java微信跳一跳操作指南

    Java微信跳一跳操作指南

    這篇文章主要為大家詳細(xì)介紹了Java微信跳一跳操作指南,通過adb來控制手機(jī)進(jìn)行操作,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • java 對(duì)象數(shù)組排序

    java 對(duì)象數(shù)組排序

    當(dāng)遇到數(shù)組排序時(shí),我們經(jīng)常會(huì)使用學(xué)過的幾種排序方法,而java 本身提供了Arrays.sort,在數(shù)據(jù)元素較少或者對(duì)效率要求不是抬高時(shí),直接使用Arrays.sort來的更容易。查看一下源碼后Arrays.sort 本身采用的是快速排序。
    2015-04-04
  • springBoot+webMagic實(shí)現(xiàn)網(wǎng)站爬蟲的實(shí)例代碼

    springBoot+webMagic實(shí)現(xiàn)網(wǎng)站爬蟲的實(shí)例代碼

    這篇文章主要介紹了springBoot+webMagic實(shí)現(xiàn)網(wǎng)站爬蟲的實(shí)例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • SpringBoot+MinIO+KKFileView實(shí)現(xiàn)文件預(yù)覽功能

    SpringBoot+MinIO+KKFileView實(shí)現(xiàn)文件預(yù)覽功能

    本文主要介紹了使用SpringBoot、MinIO和KKFileView實(shí)現(xiàn)文件上傳和在線預(yù)覽功能,通過配置MinIO存儲(chǔ)文件,并使用KKFileView生成預(yù)覽鏈接,感興趣的可以了解一下
    2024-11-11
  • IDEA上實(shí)現(xiàn)JDBC編程的方法步驟

    IDEA上實(shí)現(xiàn)JDBC編程的方法步驟

    本文主要介紹了IDEA上實(shí)現(xiàn)JDBC編程的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • 解讀String字符串拼接的原理

    解讀String字符串拼接的原理

    這篇文章主要介紹了關(guān)于String字符串拼接的原理,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • 深度解析Java中的國(guó)際化底層類ResourceBundle

    深度解析Java中的國(guó)際化底層類ResourceBundle

    做項(xiàng)目應(yīng)該都會(huì)實(shí)現(xiàn)國(guó)際化,那么大家知道Java底層是如何實(shí)現(xiàn)國(guó)際化的嗎?這篇文章就來和大家深度解析一下Java中的國(guó)際化底層類ResourceBundle,希望對(duì)大家有所幫助
    2023-03-03

最新評(píng)論

平果县| 陇西县| 白沙| 宜都市| 天津市| 松溪县| 新竹县| 台中市| 石屏县| 唐海县| 朔州市| 泾川县| 黔江区| 昭觉县| 远安县| 股票| 日喀则市| 长宁县| 卓尼县| 拜城县| 湖南省| 邯郸市| 桂林市| 宝丰县| 海城市| 重庆市| 长兴县| 宝坻区| 湘阴县| 富裕县| 安化县| 永善县| 泰安市| 玉树县| 隆回县| 孝感市| 成都市| 瑞昌市| 枣阳市| 都江堰市| 高青县|