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

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

Share

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

This article mainly explains "how to use Spring Boot to integrate Swagger", the content of the article is simple and clear, easy to learn and understand, please follow the editor's ideas slowly in depth, together to study and learn "how to use Spring Boot to integrate Swagger" bar!

Add Maven coordinat

Io.springfox springfox-swagger2 2.9.2 io.springfox springfox-swagger-ui 2.9.2

Write a configuration class

@ Configuration / / configuration class @ EnableSwagger2// enable automatic configuration of Swagger2 public class SwaggerConfig {@ Bean public Docket docket () {/ / set the environment where Swagger is to be enabled Profiles profiles = Profiles.of ("dev", "test") / / determine whether you are currently in this environment, and use enable () to receive this parameter to determine whether to enable Swagger boolean flag = environment.acceptsProfiles (profiles). Return new Docket (DocumentationType.SWAGGER_2) .groupName ("group1") / / sets the grouping to facilitate the collaborative development of .apiInfo (apiInfo ()) .enable (flag) .select () / through the .select () method To configure the scanning interface, RequestHandlerSelectors configures how to scan the interface. APIs (RequestHandlerSelectors.basePackage ("com.example.controller")) / / basePackage scans the interface under the specified packet path. Other scanning methods can click on the source code of RequestHandlerSelectors to view .build ();} / configure document information private ApiInfo apiInfo () {Contact contact = new Contact ("contact name", "http://xxx.xxx.com/ contact access link", "contact mailbox") Return new ApiInfo (/ / title "Swagger Learning", / / description "Learning to demonstrate how to configure Swagger", / / version "v1.0" / / Organization Link "http://terms.service.url/ Organization Link", / / contact Information contact, / / license "Apach 2.0 license" / / license connection "license link", / / extend new ArrayList () }}

Configure entity classes

@ ApiModel ("user entity") public class User {@ ApiModelProperty ("user name") public String username; @ ApiModelProperty ("password") public String password;}

Common notes

@ ApiOperation ("xxx API description"): acts on interface methods

@ ApiModel ("xxxPOJO description"): acts on entity classes

@ ApiModelProperty (value = "xxx attribute description", hidden = true): acts on an attribute of an entity class, and hidden is set to true to hide this attribute.

@ ApiParam ("xxx parameter description"): acts on the parameters of the interface method

Thank you for reading, the above is the content of "how to use Spring Boot to integrate Swagger", after the study of this article, I believe you have a deeper understanding of how to use Spring Boot to integrate Swagger, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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