欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

spring-boot2.7.8添加swagger的案例詳解

 更新時(shí)間:2024年01月20日 11:04:37   作者:大熊程序猿  
這篇文章主要介紹了spring-boot2.7.8添加swagger的案例詳解,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

一、新建項(xiàng)目swaggerdemo

二、修改pom.xml

注意修改:spring-boot-starter-parent版本為:2.7.8

添加依賴:

springfox-swagger2
springfox-swagger-ui
springfox-boot-starter

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.8</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.saas</groupId>
    <artifactId>swaggerdemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>com.saas.swaggerdemo</name>
    <description>com.saas.swaggerdemo</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-boot-starter</artifactId>
        <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>aliyunmaven</id>
            <name>aliyun</name>
            <url>https://maven.aliyun.com/repository/public</url>
        </repository>
        <repository>
            <id>central2</id>
            <name>central2</name>
            <url>https://repo1.maven.org/maven2/</url>
        </repository>
    </repositories>
</project>

修改:application.yml

matching-strategy: ant_path_matcher

server:
  port: 81
spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

添加SwaggerConfig

package com.saas.swaggerdemo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@EnableOpenApi
@Configuration
public class SwaggerConfig {
    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Swagger Test App Restful API")
                .description("swagger test app restful api")
                .version("1.0.0.0")
                .build();
    }
    @Bean
    public Docket createRestApi(ApiInfo apiInfo) {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo)
                .groupName("SwaggerGroupOneAPI")
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                .paths(PathSelectors.any())
                .build();
    }
}

二、添加控器器

ProductController.java

package com.saas.swaggerdemo.controllers;
import com.saas.swaggerdemo.ProductDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
@RestController
@Api(value = "ProductController")
@RequestMapping("/products")
public class ProductController {
    @ApiOperation(value = "保存產(chǎn)品")
    @PostMapping("save")
    public boolean SaveProduct(@RequestBody ProductDto productDto) {
        return true;
    }
}

ProductDto.java 

package com.saas.swaggerdemo;
public class ProductDto {
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    private  String name;
}

運(yùn)行效果:

到此這篇關(guān)于spring-boot2.7.8添加swagger的文章就介紹到這了,更多相關(guān)spring-boot2.7.8添加swagger內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 基于Springboot+Mybatis對(duì)數(shù)據(jù)訪問(wèn)層進(jìn)行單元測(cè)試的方式分享

    基于Springboot+Mybatis對(duì)數(shù)據(jù)訪問(wèn)層進(jìn)行單元測(cè)試的方式分享

    本文將介紹一種快高效、可復(fù)用的解決測(cè)試方案——對(duì)數(shù)據(jù)訪問(wèn)層做單元測(cè)試,文章通過(guò)代碼示例介紹的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下
    2023-07-07
  • Java List中數(shù)據(jù)的去重

    Java List中數(shù)據(jù)的去重

    今天小編就為大家分享一篇關(guān)于Java List中數(shù)據(jù)的去重,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-01-01
  • Java中token的存儲(chǔ)和獲取實(shí)例代碼

    Java中token的存儲(chǔ)和獲取實(shí)例代碼

    關(guān)于java獲取微信Token驗(yàn)證的問(wèn)題相信很多人都遇見過(guò),尤其是對(duì)剛接觸微信開發(fā)的人來(lái)說(shuō)確實(shí)有點(diǎn)棘手,下面這篇文章主要給大家介紹了關(guān)于Java中token存儲(chǔ)和獲取的相關(guān)資料,需要的朋友可以參考下
    2022-08-08
  • 詳解Java字符串在內(nèi)存中的存儲(chǔ)位置

    詳解Java字符串在內(nèi)存中的存儲(chǔ)位置

    這篇文章主要介紹了Java字符串在內(nèi)存中的存儲(chǔ)位置,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • 一篇文章掌握J(rèn)ava?Thread的類及其常見方法

    一篇文章掌握J(rèn)ava?Thread的類及其常見方法

    Thread類用于操作線程,是所以涉及到線程操作(如并發(fā))的基礎(chǔ)。本文將通過(guò)代碼對(duì)Thread類的功能作用及其常見方法進(jìn)行分析
    2022-03-03
  • SpringBoot集成WebSocket實(shí)現(xiàn)后臺(tái)向前端推送信息的示例

    SpringBoot集成WebSocket實(shí)現(xiàn)后臺(tái)向前端推送信息的示例

    這篇文章主要介紹了SpringBoot集成WebSocket實(shí)現(xiàn)后臺(tái)向前端推送信息的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Java并發(fā) 結(jié)合源碼分析AQS原理

    Java并發(fā) 結(jié)合源碼分析AQS原理

    這篇文章主要介紹了Java并發(fā) 結(jié)合源碼分析AQS原理,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • 詳解JAVA的控制語(yǔ)句

    詳解JAVA的控制語(yǔ)句

    這篇文章主要介紹了Java中的控制語(yǔ)句,循環(huán)等語(yǔ)句是Java編程中流程控制的基礎(chǔ),需要的朋友可以參考下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • 詳解如何使用SpringBoot封裝Excel生成器

    詳解如何使用SpringBoot封裝Excel生成器

    在軟件開發(fā)過(guò)程中,經(jīng)常需要生成Excel文件來(lái)導(dǎo)出數(shù)據(jù)或者生成報(bào)表,為了簡(jiǎn)化開發(fā)流程和提高代碼的可維護(hù)性,我們可以使用Spring Boot封裝Excel生成器,本文將介紹如何使用Spring Boot封裝Excel生成器,并提供一些示例代碼來(lái)說(shuō)明其用法和功能
    2023-06-06
  • Java8函數(shù)式接口java.util.function速查大全

    Java8函數(shù)式接口java.util.function速查大全

    因?yàn)镴ava8引入了函數(shù)式接口,在java.util.function包含了幾大類函數(shù)式接口聲明,這篇文章主要給大家介紹了關(guān)于Java8函數(shù)式接口java.util.function速查的相關(guān)資料,需要的朋友可以參考下
    2021-08-08

最新評(píng)論