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

Spring Boot Swagger3 使用方法及核心配置

 更新時(shí)間:2026年02月09日 10:13:33   作者:程序員越  
本文基于springdoc-openapi實(shí)現(xiàn),詳細(xì)介紹Swagger3在Spring Boot 項(xiàng)目中的基本使用方法、核心配置、常用注解及進(jìn)階優(yōu)化方案,感興趣的朋友跟隨小編一起看看吧

Swagger3(OpenAPI 3.0)作為 API 文檔生成工具,能幫助開發(fā)者快速構(gòu)建清晰、可交互的 API 文檔,減少前后端協(xié)作溝通成本。本文基于 springdoc-openapi 實(shí)現(xiàn),詳細(xì)介紹 Swagger3 在 Spring Boot 項(xiàng)目中的基本使用方法、核心配置、常用注解及進(jìn)階優(yōu)化方案。

一、項(xiàng)目環(huán)境與依賴配置

1. 環(huán)境要求

  • Spring Boot 版本:2.7.x 及以上(兼容 Spring Boot 3.x)
  • JDK 版本:1.8 及以上

2. 添加核心依賴

在項(xiàng)目 pom.xml 中引入 Swagger3 核心依賴(springdoc-openapi 實(shí)現(xiàn))和 Knife4j 增強(qiáng) UI 依賴(提供更友好的交互體驗(yàn)):

<!-- Swagger3 核心依賴(SpringDoc 實(shí)現(xiàn)) -->
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.5.0</version> <!-- 穩(wěn)定版本,與 Spring Boot 版本兼容 -->
</dependency>
<!-- Knife4j 增強(qiáng) UI(推薦,提供更友好的交互) -->
<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
    <version>4.5.0</version>
</dependency>

說(shuō)明:若使用 Spring Boot 3.x,需確保依賴的 jakarta 版本兼容,Knife4j 4.5.0+ 已適配 Spring Boot 3.x。

二、Swagger3 核心配置

1. 配置類編寫

創(chuàng)建 Swagger 配置類,定義 API 基本信息、安全方案、服務(wù)器環(huán)境等核心配置:

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
@Configuration
public class SwaggerConfig {
    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                // 1. API 基本信息配置
                .info(new Info()
                        .title("Spring Boot Swagger3 Demo API")  // 文檔標(biāo)題
                        .version("1.0.0")  // 接口版本
                        .description("這是一個(gè) Spring Boot Swagger3 示例項(xiàng)目,展示了 Swagger3 的核心特性(注解使用、認(rèn)證配置、多環(huán)境適配等)")  // 文檔描述
                        .contact(new Contact()  // 聯(lián)系人信息
                                .name("Example Team")
                                .email("contact@example.com")
                                .url("http://example.com")
                        )
                        .license(new License()  // 許可證信息
                                .name("Apache 2.0")
                                .url("http://springdoc.org")
                        )
                )
                // 2. 安全方案配置(JWT Bearer 認(rèn)證)
                .addSecurityItem(new SecurityRequirement().addList("bearerAuth"))
                .components(new io.swagger.v3.oas.models.Components()
                        .addSecuritySchemes("bearerAuth", new SecurityScheme()
                                .name("bearerAuth")
                                .type(SecurityScheme.Type.HTTP)
                                .scheme("bearer")
                                .bearerFormat("JWT")
                        )
                )
                // 3. 服務(wù)器環(huán)境配置(本地/測(cè)試/生產(chǎn))
                .servers(Arrays.asList(
                        new Server().url("http://localhost:8080").description("本地開發(fā)環(huán)境"),
                        new Server().url("https://staging.example.com").description("測(cè)試環(huán)境"),
                        new Server().url("https://production.example.com").description("生產(chǎn)環(huán)境")
                ));
    }
}

2. 多環(huán)境配置(application-{profile}.properties)

通過(guò)配置文件控制不同環(huán)境是否啟用 Swagger(生產(chǎn)環(huán)境建議禁用,避免接口暴露):

開發(fā)環(huán)境(application-dev.properties)

# 啟用 Swagger3 文檔
springdoc.swagger-ui.enabled=true
springdoc.api-docs.enabled=true
springdoc.openapi.enabled=true
# Swagger UI 優(yōu)化配置
springdoc.swagger-ui.operations-sorter=alpha  # 接口按字母排序(alpha=字母序,method=請(qǐng)求方法序)
springdoc.swagger-ui.tags-sorter=alpha        # 分組按字母排序
springdoc.swagger-ui.default-model-expand-depth=2  # 默認(rèn)展開模型層級(jí)(2級(jí))
springdoc.swagger-ui.default-models-expand-depth=2  # 默認(rèn)展開所有模型
springdoc.swagger-ui.path=/swagger-ui.html    # 原生 Swagger UI 訪問(wèn)路徑
knife4j.enable=true                           # 啟用 Knife4j 增強(qiáng) UI

生產(chǎn)環(huán)境(application-prod.properties)

# 生產(chǎn)環(huán)境禁用 Swagger(安全考慮)
springdoc.swagger-ui.enabled=false
springdoc.api-docs.enabled=false
springdoc.openapi.enabled=false
knife4j.enable=false                          # 禁用 Knife4j UI

三、常用注解與實(shí)戰(zhàn)示例

Swagger3 通過(guò)注解描述 API 接口、參數(shù)、響應(yīng)和數(shù)據(jù)模型,以下是核心注解的實(shí)戰(zhàn)用法(基于控制器和實(shí)體類):

1. 接口分組:@Tag

用于標(biāo)記控制器或接口組,方便文檔分類展示,支持關(guān)聯(lián)外部文檔:

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.externalDocs.ExternalDocumentation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/users")
@Tag(
    name = "用戶管理",  // 分組名稱(文檔中顯示的分組標(biāo)簽)
    description = "用戶相關(guān)核心接口,包含用戶查詢、創(chuàng)建、更新、刪除等 CRUD 操作",  // 分組描述
    externalDocs = @ExternalDocumentation(  // 外部文檔鏈接(可選)
        url = "http://example.com/docs/user-api",
        description = "用戶管理 API 詳細(xì)設(shè)計(jì)文檔"
    )
)
public class UserController {
    // 接口實(shí)現(xiàn)...
}

2. 接口描述:@Operation

用于描述具體接口的功能、用途,支持指定接口排序:

import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Operation(
    summary = "分頁(yè)查詢所有用戶",  // 接口簡(jiǎn)要說(shuō)明(文檔列表頁(yè)顯示)
    description = "支持按頁(yè)碼和每頁(yè)大小分頁(yè),返回用戶列表及分頁(yè)信息(總條數(shù)、總頁(yè)數(shù))",  // 詳細(xì)描述
    tags = {"用戶管理"},  // 所屬分組(與 @Tag 名稱一致)
    position = 1  // 接口排序權(quán)重(數(shù)值越小越靠前)
)
@GetMapping
public ResponseEntity<PageResponse> getAllUsers(
    @RequestParam(defaultValue = "1") Integer page,  // 頁(yè)碼(默認(rèn)1)
    @RequestParam(defaultValue = "10") Integer size  // 每頁(yè)大?。J(rèn)10)
) {
    // 業(yè)務(wù)邏輯:查詢分頁(yè)用戶數(shù)據(jù)
    Page<User> userPage = userService.listUsers(page - 1, size); // page 從 0 開始
    PageResponse pageResponse = new PageResponse<>(
        userPage.getContent(),
        userPage.getTotalElements(),
        userPage.getTotalPages(),
        page,
        size
    );
    return ResponseEntity.ok(ApiResponse.success(pageResponse));
}

3. 請(qǐng)求參數(shù)描述:@Parameter

用于描述請(qǐng)求參數(shù)(路徑參數(shù)、查詢參數(shù)、請(qǐng)求頭),明確參數(shù)含義、示例值和約束:

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.models.enums.ParameterIn;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@Operation(summary = "根據(jù) ID 查詢用戶", description = "通過(guò)用戶唯一 ID 獲取用戶詳情", position = 2)
@GetMapping("/{id}")
public ResponseEntity<ApiResponse> getUserById(
    @Parameter(
        description = "用戶唯一 ID",  // 參數(shù)說(shuō)明
        example = "1001",  // 示例值(文檔中可直接使用)
        in = ParameterIn.PATH,  // 參數(shù)位置:PATH/QUERY/HEADER
        required = true,  // 是否必填(默認(rèn) false)
        name = "id"  // 參數(shù)名稱(與 @PathVariable 一致)
    )
    @PathVariable Long id
) {
    User user = userService.getUserById(id);
    if (user == null) {
        return ResponseEntity.ok(ApiResponse.fail("用戶不存在"));
    }
    return ResponseEntity.ok(ApiResponse.success(user));
}

4. 響應(yīng)說(shuō)明:@ApiResponses + @ApiResponse

定義接口可能的響應(yīng)狀態(tài)碼、描述和響應(yīng)格式,幫助前端理解返回邏輯:

import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@Operation(summary = "創(chuàng)建用戶", description = "新增用戶信息,用戶名不可重復(fù)", position = 3)
@ApiResponses({
    @ApiResponse(
        responseCode = "201",  // 響應(yīng)狀態(tài)碼(創(chuàng)建成功)
        description = "用戶創(chuàng)建成功",
        content = @Content(
            mediaType = "application/json",
            schema = @Schema(implementation = ApiResponse.class)  // 響應(yīng)數(shù)據(jù)模型
        )
    ),
    @ApiResponse(responseCode = "400", description = "請(qǐng)求參數(shù)錯(cuò)誤(如用戶名長(zhǎng)度不足、郵箱格式錯(cuò)誤)"),
    @ApiResponse(responseCode = "409", description = "用戶名已存在(沖突)"),
    @ApiResponse(responseCode = "500", description = "服務(wù)器內(nèi)部錯(cuò)誤")
})
@PostMapping
public ResponseEntity<ApiResponse> createUser(
    @RequestBody User user  // 請(qǐng)求體(下文詳細(xì)描述)
) {
    boolean success = userService.createUser(user);
    if (success) {
        return ResponseEntity.status(201).body(ApiResponse.success(user));
    }
    return ResponseEntity.ok(ApiResponse.fail("創(chuàng)建失敗"));
}

5. 請(qǐng)求體描述:@RequestBody

用于描述 POST/PUT 等請(qǐng)求的請(qǐng)求體,明確請(qǐng)求格式、示例值和必填項(xiàng):

import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.media.ExampleObject;
@PostMapping
public ResponseEntity<ApiResponse> createUser(
    @RequestBody(
        description = "用戶創(chuàng)建請(qǐng)求參數(shù)",
        required = true,  // 是否必填
        content = @Content(
            mediaType = "application/json",
            examples = @ExampleObject(  // 請(qǐng)求體示例(文檔中可直接復(fù)制使用)
                name = "創(chuàng)建用戶示例",
                value = "{\"username\": \"test_user\", \"password\": \"123456a\", \"email\": \"test@example.com\", \"age\": 25, \"active\": true}"
            ),
            schema = @Schema(implementation = User.class)  // 請(qǐng)求體數(shù)據(jù)模型
        )
    )
    @org.springframework.web.bind.annotation.RequestBody User user
) {
    // 業(yè)務(wù)邏輯...
}

6. 數(shù)據(jù)模型描述:@Schema

用于描述實(shí)體類及其字段,明確字段含義、示例值、數(shù)據(jù)格式和約束:

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description = "用戶實(shí)體類(存儲(chǔ)用戶核心信息)")
public class User {
    @Schema(
        description = "用戶唯一 ID",
        example = "1001",
        accessMode = Schema.AccessMode.READ_ONLY  // 只讀字段(創(chuàng)建時(shí)無(wú)需傳入)
    )
    private Long id;
    @Schema(
        description = "用戶名(登錄賬號(hào))",
        example = "admin",
        requiredMode = Schema.RequiredMode.REQUIRED,  // 必填字段
        minLength = 3,  // 最小長(zhǎng)度
        maxLength = 20,  // 最大長(zhǎng)度
        pattern = "^[a-zA-Z0-9_]+$"  // 正則表達(dá)式(僅允許字母、數(shù)字、下劃線)
    )
    private String username;
    @Schema(
        description = "用戶郵箱",
        example = "admin@example.com",
        format = "email",  // 數(shù)據(jù)格式(郵箱格式校驗(yàn))
        requiredMode = Schema.RequiredMode.REQUIRED
    )
    private String email;
    @Schema(
        description = "用戶年齡",
        example = "28",
        minimum = "1",  // 最小值
        maximum = "120",  // 最大值
        requiredMode = Schema.RequiredMode.NOT_REQUIRED  // 非必填
    )
    private Integer age;
    @Schema(
        description = "賬號(hào)狀態(tài)(true=啟用,false=禁用)",
        example = "true",
        defaultValue = "true"  // 默認(rèn)值
    )
    private Boolean active;
}

四、進(jìn)階功能配置

1. 全局參數(shù)配置

若項(xiàng)目中所有接口都需要攜帶固定參數(shù)(如 X-Request-Id 請(qǐng)求頭),可在 SwaggerConfig 中添加全局參數(shù):

import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.media.Schema;
import java.util.Collections;
@Bean
public OpenAPI customOpenAPI() {
    // 全局請(qǐng)求頭參數(shù):X-Request-Id(用于鏈路追蹤)
    Parameter globalRequestId = new Parameter()
            .name("X-Request-Id")
            .description("請(qǐng)求唯一標(biāo)識(shí)(用于鏈路追蹤)")
            .in(ParameterIn.HEADER)
            .required(false)
            .schema(new Schema().example("req-20240520123456"));
    return new OpenAPI()
            .info(...)  // 原有信息配置
            .addSecurityItem(...)  // 原有安全配置
            .components(...)  // 原有組件配置
            .servers(...)  // 原有服務(wù)器配置
            .addParametersItem(globalRequestId);  // 添加全局參數(shù)
}

2. 分組排序優(yōu)化

通過(guò) extensions 配置分組排序,讓文檔分組更符合業(yè)務(wù)邏輯:

import java.util.Arrays;
import java.util.HashMap;
import java.util.Collections;
@Bean
public OpenAPI customOpenAPI() {
    return new OpenAPI()
            .info(...)
            .addSecurityItem(...)
            .components(...)
            .servers(...)
            // 分組排序配置
            .extensions(Collections.singletonMap(
                "x-tagGroups",
                Arrays.asList(
                    new HashMap<String, Object>() {{
                        put("name", "核心業(yè)務(wù)");
                        put("tags", Arrays.asList("用戶管理", "訂單管理"));
                        put("order", 1);  // 分組排序權(quán)重(數(shù)值越小越靠前)
                    }},
                    new HashMap<String, Object>() {{
                        put("name", "基礎(chǔ)功能");
                        put("tags", Arrays.asList("產(chǎn)品管理", "系統(tǒng)配置"));
                        put("order", 2);
                    }}
                )
            ));
}

3. 忽略指定接口、參數(shù)

  • 忽略接口:使用 @Hidden 注解(該接口不會(huì)顯示在文檔中)
import io.swagger.v3.oas.annotations.Hidden;
@Hidden
@GetMapping("/internal")  // 內(nèi)部接口,不對(duì)外暴露
public ResponseEntity() {
    return ResponseEntity.ok("內(nèi)部接口返回");
}
  • 忽略參數(shù):在 @Parameter 中設(shè)置 hidden = true
@GetMapping("/info")
public ResponseEntity<ApiResponse>(
    @Parameter(hidden = true)  // 隱藏該參數(shù)(不顯示在文檔中)
    @RequestParam String secretKey  // 內(nèi)部校驗(yàn)參數(shù),無(wú)需前端關(guān)注
) {
    // 業(yè)務(wù)邏輯...
}

4. 自定義響應(yīng)示例(續(xù))

@ApiResponses({
    @ApiResponse(
        responseCode = "200",
        description = "操作成功",
        content = @Content(
            mediaType = "application/json",
            examples = @ExampleObject(
                name = "成功示例",
                value = "{\"code\": 200, \"message\": \"操作成功\", \"data\": {\"id\": 1001, \"username\": \"admin\", \"email\": \"admin@example.com\"}}"
            )
        )
    ),
    @ApiResponse(
        responseCode = "400",
        description = "參數(shù)錯(cuò)誤",
        content = @Content(
            mediaType = "application/json",
            examples = @ExampleObject(
                name = "參數(shù)錯(cuò)誤示例",
                value = "{\"code\": 400, \"message\": \"用戶名長(zhǎng)度不能小于3位\", \"data\": null}"
            )
        )
    )
})
@PostMapping
public ResponseEntity<ApiResponse> createUser(@RequestBody User user) {
    // 業(yè)務(wù)邏輯...
}

5. 集成 Spring Security 權(quán)限控制

若項(xiàng)目使用 Spring Security 進(jìn)行權(quán)限管理,可通過(guò) Swagger 配置實(shí)現(xiàn)認(rèn)證聯(lián)動(dòng),讓文檔支持?jǐn)y帶令牌訪問(wèn)受保護(hù)接口:

import io.swagger.v3.oas.models.security.OAuthFlow;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.Scopes;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(...)  // 原有信息配置
                // 配置 OAuth2 認(rèn)證(密碼模式)
                .addSecurityItem(new SecurityRequirement().addList("oauth2"))
                .components(new io.swagger.v3.oas.models.Components()
                        .addSecuritySchemes("oauth2", new SecurityScheme()
                                .type(SecurityScheme.Type.OAUTH2)
                                .flows(new OAuthFlows()
                                        .password(new OAuthFlow()
                                                .tokenUrl("http://localhost:8080/oauth2/token")  // 令牌獲取地址
                                                .scopes(new Scopes()
                                                        .addString("read", "讀取權(quán)限")
                                                        .addString("write", "寫入權(quán)限")
                                                )
                                        )
                                )
                        )
                )
                .servers(...);  // 原有服務(wù)器配置
    }
}

補(bǔ)充:需在 Spring Security 配置中放行 Swagger 相關(guān)路徑,避免被攔截:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
public class SecurityConfig {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(auth -> auth
                // 放行 Swagger 相關(guān)路徑
                .requestMatchers("/swagger-ui/**", "/v3/api-docs/**", "/knife4j/**").permitAll()
                .anyRequest().authenticated()
        );
        return http.build();
    }
}

五、文檔訪問(wèn)與調(diào)試

1. 訪問(wèn)地址

配置完成后,啟動(dòng)項(xiàng)目,通過(guò)以下地址訪問(wèn) Swagger 文檔:

  • 原生 Swagger UI:http://localhost:8080/swagger-ui.html
  • Knife4j 增強(qiáng) UI(推薦):http://localhost:8080/doc.html
  • OpenAPI 規(guī)范 JSON:http://localhost:8080/v3/api-docs

2. 在線調(diào)試流程

  1. 打開 Knife4j UI 地址,在文檔頂部選擇對(duì)應(yīng)的服務(wù)器環(huán)境(如本地開發(fā)環(huán)境);
  2. 若配置了認(rèn)證(JWT/OAuth2),點(diǎn)擊頁(yè)面右上角「授權(quán)」按鈕,輸入令牌或完成認(rèn)證流程;
  3. 選擇目標(biāo)接口,點(diǎn)擊「調(diào)試」按鈕,填寫請(qǐng)求參數(shù)(路徑參數(shù) / 查詢參數(shù) / 請(qǐng)求體);
  4. 點(diǎn)擊「發(fā)送」按鈕,查看響應(yīng)結(jié)果(狀態(tài)碼、響應(yīng)體、響應(yīng)頭)。

六、常見問(wèn)題排查

1. 文檔頁(yè)面無(wú)法訪問(wèn)

  • 檢查 springdoc.swagger-ui.enabledknife4j.enable 配置是否為 true(開發(fā)環(huán)境);
  • 確認(rèn)依賴版本與 Spring Boot 版本兼容(如 Spring Boot 3.x 需使用 Knife4j 4.5.0+);
  • 排查 Spring Security 或攔截器是否攔截了 Swagger 相關(guān)路徑,需手動(dòng)放行。

2. 接口未顯示在文檔中

  • 檢查控制器是否添加 @RestController 注解,接口是否添加 HTTP 注解(@GetMapping/@PostMapping 等);
  • 確認(rèn)接口方法是否為 public 權(quán)限(非 public 方法不會(huì)被掃描);
  • 檢查是否誤加 @Hidden 注解,或是否配置了接口掃描范圍限制。

3. 注解不生效

  • 確認(rèn)導(dǎo)入的是 io.swagger.v3.oas.annotations 包下的注解(而非 Swagger2 的 io.swagger.annotations);
  • 檢查依賴是否完整(核心依賴 springdoc-openapi-starter-webmvc-ui 不可缺失)。

七、總結(jié)

Swagger3(OpenAPI 3.0)通過(guò) springdoc-openapi 與 Spring Boot 項(xiàng)目無(wú)縫集成,僅需簡(jiǎn)單配置和注解,即可生成規(guī)范、可交互的 API 文檔,大幅降低前后端協(xié)作成本。

核心優(yōu)勢(shì)

  1. 實(shí)時(shí)同步:接口變更時(shí),文檔自動(dòng)更新,避免「文檔與代碼不一致」問(wèn)題;
  2. 在線調(diào)試:支持直接在文檔頁(yè)面發(fā)送請(qǐng)求,無(wú)需依賴 Postman 等第三方工具;
  3. 靈活擴(kuò)展:支持 JWT/OAuth2 認(rèn)證、全局參數(shù)、分組排序等高級(jí)功能;
  4. 友好交互:Knife4j 增強(qiáng) UI 提供更直觀的操作體驗(yàn),支持文檔導(dǎo)出(PDF/Markdown)。

最佳實(shí)踐

  1. 開發(fā)環(huán)境啟用 Swagger,生產(chǎn)環(huán)境強(qiáng)制禁用(避免接口暴露風(fēng)險(xiǎn));
  2. 接口注解需完整(@Tag+@Operation+@ApiResponses),參數(shù)和模型添加 @Parameter/@Schema 說(shuō)明;
  3. 結(jié)合 Spring Security 配置權(quán)限控制,保障文檔訪問(wèn)安全;
  4. 定期更新依賴版本,確保兼容性和安全性。
    通過(guò)本文的配置和示例,開發(fā)者可快速上手 Swagger3,并根據(jù)項(xiàng)目需求靈活擴(kuò)展功能,讓 API 文檔成為前后端協(xié)作的「橋梁」而非「負(fù)擔(dān)」。

到此這篇關(guān)于Spring Boot Swagger3 使用指南的文章就介紹到這了,更多相關(guān)Spring Boot Swagger3 使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java操作Elasticsearch?rest-high-level-client?的基本使用

    Java操作Elasticsearch?rest-high-level-client?的基本使用

    這篇文章主要介紹了Java操作Elasticsearch?rest-high-level-client?的基本使用,本篇主要講解一下?rest-high-level-client?去操作?Elasticsearch的方法,結(jié)合實(shí)例代碼給大家詳細(xì)講解,需要的朋友可以參考下
    2022-10-10
  • JavaCV實(shí)現(xiàn)將視頻以幀方式抽取

    JavaCV實(shí)現(xiàn)將視頻以幀方式抽取

    這篇文章主要為大家詳細(xì)介紹了JavaCV實(shí)現(xiàn)將視頻以幀方式抽取,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • Centos6.5下Jdk+Tomcat+Mysql環(huán)境安裝圖文教程

    Centos6.5下Jdk+Tomcat+Mysql環(huán)境安裝圖文教程

    這篇文章主要為大家詳細(xì)介紹了Centos6.5系統(tǒng)下Jdk+Tomcat+Mysql環(huán)境安裝過(guò)程,感興趣的小伙伴們可以參考一下
    2016-05-05
  • SpringCache輕松啟用Redis緩存的全過(guò)程

    SpringCache輕松啟用Redis緩存的全過(guò)程

    Spring Cache是Spring提供的一種緩存抽象機(jī)制,旨在通過(guò)簡(jiǎn)化緩存操作來(lái)提高系統(tǒng)性能和響應(yīng)速度,本文將給大家詳細(xì)介紹SpringCache如何輕松啟用Redis緩存,文中有詳細(xì)的代碼示例供大家參考,需要的朋友可以參考下
    2024-07-07
  • Java如何在Map中存放重復(fù)key

    Java如何在Map中存放重復(fù)key

    這篇文章主要介紹了Java如何在Map中存放重復(fù)key,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • Java中HashSet、LinkedHashSet和TreeSet區(qū)別詳解

    Java中HashSet、LinkedHashSet和TreeSet區(qū)別詳解

    這篇文章主要介紹了Java中HashSet、LinkedHashSet和TreeSet區(qū)別詳解,如果你需要一個(gè)訪問(wèn)快速的Set,你應(yīng)該使用HashSet,當(dāng)你需要一個(gè)排序的Set,你應(yīng)該使用TreeSet,當(dāng)你需要記錄下插入時(shí)的順序時(shí),你應(yīng)該使用LinedHashSet,需要的朋友可以參考下
    2023-09-09
  • SpringBoot如何實(shí)現(xiàn)定時(shí)任務(wù)示例詳解

    SpringBoot如何實(shí)現(xiàn)定時(shí)任務(wù)示例詳解

    使用定時(shí)任務(wù)完成一些業(yè)務(wù)邏輯,比如天氣接口的數(shù)據(jù)獲取,定時(shí)發(fā)送短信,郵件。以及商城中每天用戶的限額,定時(shí)自動(dòng)收貨等等,這篇文章主要給大家介紹了關(guān)于SpringBoot如何實(shí)現(xiàn)定時(shí)任務(wù)的相關(guān)資料,需要的朋友可以參考下
    2021-10-10
  • SpringBoot圖片上傳和訪問(wèn)路徑映射

    SpringBoot圖片上傳和訪問(wèn)路徑映射

    這篇文章主要為大家詳細(xì)介紹了SpringBoot圖片上傳和訪問(wèn)路徑映射,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • java實(shí)現(xiàn)發(fā)牌小程序

    java實(shí)現(xiàn)發(fā)牌小程序

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)發(fā)牌小程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • JavaScript實(shí)現(xiàn)貪吃蛇游戲

    JavaScript實(shí)現(xiàn)貪吃蛇游戲

    這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)貪吃蛇游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06

最新評(píng)論

潞城市| 开江县| 绥德县| 东莞市| 探索| 临朐县| 阿克| 荥阳市| 博白县| 敦化市| 龙陵县| 红安县| 五河县| 岳西县| 嵊州市| 玛多县| 永登县| 黄石市| 西宁市| 兰州市| 罗平县| 昭苏县| 营山县| 靖远县| 合肥市| 巨鹿县| 孟津县| 中卫市| 东明县| 图片| 田东县| 渝中区| 长葛市| 花垣县| 抚顺市| 沐川县| 珠海市| 集贤县| 措美县| 勃利县| 吉林市|