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

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

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

一、添加依賴(lài)

<!--SpringBoot使用Swagger2構(gòu)建API文檔的依賴(lài)-->
    <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配置類(lèi)

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//表示該類(lèi)為一個(gè)配置類(lèi),相當(dāng)于spring中的xml配置文件
@EnableSwagger2 //開(kāi)啟在線文檔
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 增加文檔注釋

通過(guò)@ApiOperation注解來(lái)給API增加說(shuō)明

通過(guò)@ApiImplicitParams@ApiImplicitParam注解來(lái)給參數(shù)增加說(shuō)明

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用戶(hù)信息", notes="根據(jù)id查找用戶(hù)信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "用戶(hù)ID", required = true, dataType = "Integer"),
  })
  public User getUserById(Integer id){
    User user = userDao.getOne(id);
    return user;
  }

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

四、查看Swagger2文檔

重啟項(xiàng)目

訪問(wèn):

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

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

相關(guān)文章

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

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

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

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

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

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

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

    Java微信跳一跳操作指南

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

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

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

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

    這篇文章主要介紹了springBoot+webMagic實(shí)現(xiàn)網(wǎng)站爬蟲(chóng)的實(shí)例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(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ù)覽功能,通過(guò)配置MinIO存儲(chǔ)文件,并使用KKFileView生成預(yù)覽鏈接,感興趣的可以了解一下
    2024-11-11
  • IDEA上實(shí)現(xiàn)JDBC編程的方法步驟

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

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

    解讀String字符串拼接的原理

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

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

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

最新評(píng)論

禄丰县| 通城县| 萍乡市| 龙海市| 龙江县| 广昌县| 山丹县| 惠东县| 阿图什市| 浠水县| 青川县| 长寿区| 晋江市| 龙里县| 新平| 乌拉特中旗| 侯马市| 吴堡县| 陈巴尔虎旗| 祁阳县| 迁西县| 高雄县| 乌拉特中旗| 和田市| 盐边县| 连江县| 南川市| 陇南市| 北宁市| 泗水县| 永嘉县| 阿尔山市| 贡山| 苏州市| 泉州市| 屏东县| 松桃| 巴青县| 志丹县| 堆龙德庆县| 都江堰市|