“This is the 8th day of my participation in the First Challenge 2022. For details: First Challenge 2022”

👨🎓 Author: Bug Bacteria

✏️ blog: CSDN, Nuggets, etc

💌 public account: Magic House of the Circle of the Apes

🚫 special statement: original is not easy, reprint please attach the original source link and this article statement, thank you for your cooperation.

🙏 Copyright notice: part of the text or pictures in the article may come from the Internet or Baidu Encyclopedia, if there is infringement, please contact bug bacteria processing.

Hi, family. I’m the bug. Here I go again. Today we are going to talk about something, OK, and we will continue the Series of articles on SpringBoot. Hope to help more beginners quickly start!

Friends in the process of reviewing the article if you feel that the article has a little help, but also please don’t mean your hand like it, bold to light up the article 👍, your like three even (collect ⭐️+ pay attention to 👨 port + message board) is the best encouragement and support to bug bacteria on my creation road. Time does not abandon, creation, refueling!

One, foreword

This issue is mainly for springBoot how to integrate Swagger interface documents for the overall review, and give you popular science under swagger common core notes.

In the last two sessions, we demonstrated how to integrate Swagger online interface documentation on the basis of springBoot architecture, and then used common apis to demonstrate and some UI changes of online documentation.

If there is a friend to insert directly see the article, I must be going to advise you to return the two stage, after all, teaching bug bacteria never are the progressive transformation of gradualism, not a sigh of relief to instill knowledge so much, sense of purpose is to enhance readers, the second is directly digest, three in order not to let everyone has read the burden…

One knowledge a day is enough. If you feel this way is not appropriate, you can also ask, I mainly serve to serve you, if there is a better suggestion, I will take it.

Next, I will explain to you some model APIS used in the integration of Swagger project. Please follow me. It has good popularization value and is also used in daily development.

Swagger

Since Swagger generates the corresponding API through annotations, we need to add various annotations to describe the interface, so we must be clear about its commonly used annotations, otherwise I will just talk about these in vain.

Next I will explain the use of Swagger annotation in detail in this tutorial. Please listen carefully ~

1. @ API

Function: Modifies the entire class and describes what Controller does.

Code demo:

@restController @requestMapping ("/user") @API (tags = "UserController ",description =" UserController ") Public Class UserController {}Copy the code

Demo screenshot:

2, @ ApiOpration

Function: Describes a method, or interface, of a class.

Code demo:

@getMapping ("/get-users") @apiOperation (value = "not pagingquery all user information ",notes =" not pagingquery all user information ") public List<UserEntity> getUserList() { }Copy the code

Demo screenshot:

3, @ ApiParam

Function: Describes a single parameter.

Code demo:

@getMapping ("/ getuser-by-id ") @APIOperation (value = "Query user information by user ID ",notes =" Query user information by user ID ") public UserEntity GetUserById (@requestParam (name = "userId") @APIParam (" please enter userId") String userId){return usermapper.getUserById (userId); }Copy the code

Demo screenshot:

4, @ ApiModel

Uses an object to receive arguments.

Code demo:

@apiModel (value = "QueryUserInfoModel ",description =" QueryUserInfoModel ") public class QueryUserInfoModel {}Copy the code

Demo screenshot:

5, @ ApiModelProperty

Used to describe a field in an object that receives a parameter.

Code demo:

@APIModelProperty (" Sender email account ") private String sendMailAccount; @apiModelProperty (" recipient email account ") private String acceptMailAccount;Copy the code

Demo screenshot:

6, @ ApiIgnore

Function: Can be used in classes, methods, method parameters, to mask some interface or parameter, so that it is not displayed on the page.

Code demo 1: Use it on classes

@APIIgnore @restController @requestMapping ("/user") @API (tags = "user management module ",description =" user management module ") public class UserController { }Copy the code

Code Demo 2: Use it on methods

@apiignore @getMapping ("/get-users") @apiOperation (value = "not paging query db all user information ",notes =" not paging query DB all user information ") public ListgetUserList() { return userService.getUsers(); }Copy the code

If the interface is not online or not perfect, we can add this annotation, so that the colleagues using Swagger document will not see this interface, so as to avoid unnecessary trouble, interface error? What’s wrong with the logic of this interface? And so on the question, is not very convenient, secondly, you do not need to comment out or delete, so this annotation we still want to practice to deepen the impression.

** Note: ** the following introduction to several is not often used, we should expand it ~ to understand the main ha. You don’t have to spend time digging into it.

7, @ ApiResponse

Purpose: Used in combination with @APIresponses on Rest interfaces or classes to assemble return parameter descriptions.

8, @ ApiResponses

Purpose :HTTP response overall description.

9, @ ApiError

Action: Information returned when an error occurs.

10, @ ApiImplicitParam

Action: A request parameter.

11, @ ApiImplicitParams

Action: Multiple request parameters.

. .

In fact, there are some API, I will list one by one, rely on you to draw inferring.

Third, summary

After all, Swagger stores information in its defined description file (in YML or JSON format), which can be maintained to update interface documentation and generate side code. Springfox-swagger, on the other hand, can scan the code to generate the description file without having to maintain the description file. All the information is in the code. The code is the interface documentation, the interface documentation is the code, and the online documentation alone does 90 percent of the writing and maintenance of the documentation for us, thanks to the open source gurus for their contributions.

Why springfox-Swagger? Swagger is a technology that follows the OpenAPI specification, and SpringFox is an implementation of that technology. Just like AOP and DI in Spring, the former is the idea and the latter is the implementation.

. .

OK, that’s all for this episode. If you have any questions, feel free to comment in the comments section. See you next time.

Four, the past popular recommendation

How to integrate Swagger2 with Springboot

How to integrate Swagger2 with Springboot

Springboot series (12) : How to code the configuration of sending email reminders

Springboot series (12) : how to code a simple email send

Springboot series (12) : how to code the picture with attachment mail

Springboot series (12) : how to code the implementation of static template mail

Springboot series (12) : how to achieve the code to send a large copy of the mail – attached complete code

. .

If you want to learn more, you can pay attention to the bug bug column “SpringBoot Zero-based Introduction”, from scratch, from zero to one! Hope I can help you.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

☘️ Be who you want to be, there is no time limit, you can start whenever you want,

🍀 You can change from now on, you can also stay the same, this thing, there are no rules to speak of, you can live the most wonderful yourself.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

💓 If this article is helpful to you, please leave a like! (# ^. ^ #);

💝 if you like the article shared by bug fungus, please give bug fungus a point of concern! (๑ ‘ᴗ ‵ ๑);

💗 if you have any questions about the article, please also leave a message at the end of the article or add a group [QQ communication group :708072830];

💞 In view of the limited personal experience, all views and technical research points, if you have any objection, please directly reply to participate in the discussion (do not post offensive comments, thank you);

💕 copyright notice: original is not easy, reprint please attach the original source link and this article statement, all rights reserved, piracy will investigate!! thank you