Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate Swagger3 with SpringBoot

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how SpringBoot integrates Swagger3. It is very detailed and has certain reference value. Friends who are interested must finish it!

First, what is swagger?

1. Swagger is a standard and complete document framework.

Used to generate, describe, invoke, and visualize RESTful-style Web service documents

Official website: https://swagger.io/

2. What you should pay attention to when using swagger:

Swagger must be turned off in a production environment

It itself is only used for communication between front and rear engineers.

A dedicated internal server can be used to display ui for access

Even if you have to take good safety measures up here.

3, because swagger3.0.0 has been released, this article uses the latest version

If you are still using version 2.x, please refer to it and pay attention to the distinction.

Second, SpringBoot integrates swagger3

Pom.xml integrated Swagger3 dependency

Io.springfox springfox-boot-starter 3.0.0 org.springframework.plugin spring-plugin-core Org.springframework.plugin spring-plugin-metadata

Swagger3 configuration object definition

Import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration; 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.service.Contact;import springfox.documentation.spi.DocumentationType;import springfox.documentation.spring.web.plugins.Docket @ Configuration@EnableOpenApipublic class Swagger3Config {@ Bean public Docket createRestApi () {return new Docket (DocumentationType.OAS_30) .apiInfo (apiInfo ()) .select () .apis (RequestHandlerSelectors.basePackage ("com.digipower.controller")) .build (PathSelectors.any ()) } private ApiInfo apiInfo () {return new ApiInfoBuilder (). Title ("on the road of struggle-Wechat reservation and file search system"). TermsOfServiceUrl ("https://blog.csdn.net/zhouzhiwengang") .description (" API interface ") .contact (new Contact (" https://blog.csdn.net/zhouzhiwengang","", ") ") .version (" 3.0") .build () }}

Screenshot of SpringBoot integrated Swagger3 interface document effect

SpringBoot access Swagger3 interface document address

Default interface access address: http://192.168.0.1:5988/swagger-ui/

Third, the use of swagger3 comment tags

@ ApiModel is used to describe the function above the class.

@ ApiModelProperty is used to describe the function on the field

Screenshot of the column:

@ Api is used to specify a general description of each interface in a controller

@ ApiOperation is used to illustrate a method

@ ApiImplicitParams: used to contain multiple @ ApiImplicitParam

@ ApiImplicitParam: used to describe a request parameter

Screenshot of the column:

Warm reminder: for any request parameter structure description, please remember to add the @ ApiParam tag. If you do not add the @ ApiParam tag, the parameter structure description will be empty in the Swagger3 document.

The above is all the content of the article "how SpringBoot integrates Swagger3". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report