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 Swagger-UI with Spring Boot

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article shows you how Spring Boot integrates Swagger-UI. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Swagger-UI

The following describes how to integrate Swagger-UI with spring boot to realize the project's online interface document.

A brief introduction to Swagger-UI

Swagger is a framework for online automatic generation and testing of documents with Restful style interface.

Introduction to Swagger-UI on the official website:

To put it simply: Swagger provides a set of static pages, which can be integrated in the SpringBoot application, visit the static pages directly, and open the specified Swagger specification to display and test the calling interface:

Integrating Swagger into SpringBoot is very easy, just adding a few simple annotations.

The effect is as shown in the figure:

II. Pom dependence

3. Pom configure Swagger2Config class

The Swagger2Config class is located in the config package and is used to configure swagger.

Introduce some simple configurations:

The generation scope of API interface documents

Swagger has three different choices for the scope of generating API documents

Under the API document that generates the class with the specified envelope

Generate an API document for the class with the specified annotation

Generate an API document with the specified annotated method

Three ways are shown in the figure:

Configure page information

The corresponding relationship is shown in the figure.

Fourth, comment on the configuration of the transaction class.

Common notes

@ Api: used to modify the Controller class to generate Controller-related document information

@ ApiOperation: used to modify methods in the Controller class to generate documentation information about interface methods

@ ApiParam: used to modify the parameters in the interface and generate documentation information related to the parameters of the interface.

@ ApiModelProperty: used to modify the attributes of the entity class. When the entity class is a request parameter or returns a result, the relevant document information is generated directly.

@ Api

Value-Field description

Description-comments that describe this class

Corresponding to:

@ ApiOperation

Value-Field description

Notes-comment description

HttpMethod-indicates how this method is requested

Type-response of the return value of the method

@ ApiModelProperty

Value- field description

Name- overrides property names

DataType- overrides attribute types

Is required- required

Example- gives an example

Hidden- hiding

@ ApiResponse

Code-HTTP status code of the response

Message-the information content of the response

5. Authorizations

If the project integrates user authentication such as OAuth3 or JWT, you cannot directly call the need to add authorizations.

You can get it from the console, and you can call it freely after you add it.

VI. Document call

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

Look at the version information

Http://localhost:8080/swagger-resources/

The above is how Spring Boot integrates Swagger-UI. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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

Internet Technology

Wechat

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

12
Report