Example of using swagger2 in spring boot project

This article introduces an example of using swagger2 in the spring boot project and shares it with you as follows:

Add swagger2 dependency

In POM Adding the dependency of swagger2 to XML

Create swagger2 configuration class

In application Create the configuration class swagger2 of swagger2 at the same level of Java.

Add document content

After completing the above configuration, we can actually produce document content, but such documents are mainly for the request itself, and the description is mainly generated from the naming of functions, which is not friendly to users. We usually need to add some instructions to enrich the document content.

View API

Start the spring boot program and visit: http://localhost:8080/swagger -ui. html

API document access and debugging

In addition to viewing interface functions, swagger also provides debugging and testing functions, We can click the model schema (yellow area: it indicates the data structure) on the right in the figure above. At this time, there is the template of the user object in the value. We only need to modify it slightly. Click the try it out! Button below to complete a request call! Several get requests can be used to verify whether the previous post request is correct.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>