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 use swagger and knife in Springboot

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Springboot in how to use swagger and knife, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Swagger2 dependency package compile group: 'io.springfox', name:' springfox-swagger2', version: '2.9.2'

Compile group: 'io.springfox', name:' springfox-swagger-ui', version: '2.9.2'

/ / the following two packages are used to prevent warning logs thrown when comments are not given default values.

Compile group: 'io.swagger', name:' swagger-annotations', version: '1.5.22'

Compile group: 'io.swagger', name:' swagger-models', version: '1.5.22'

Configure @ Getter

@ Setter

@ Configuration

@ EnableSwagger2

@ ConfigurationProperties ("swagger")

Public class SwaggerConfig {

Private String host;// Custom host

@ Bean

Public Docket createRestApi () {

Return new Docket (DocumentationType.SWAGGER_2)

.apiInfo (apiInfo ())

.select ()

.apis (RequestHandlerSelectors.basePackage ("com.only.oc.web.api")) / / scan package

.apis (RequestHandlerSelectors.withClassAnnotation (Api.class)) / / scan the contorller annotated in API

.apis (RequestHandlerSelectors.withMethodAnnotation (ApiOperation.class)) / / scan the method with ApiOperation annotations

.notify (PathSelectors.any ())

.build () .host (host); / / Custom host

}

Private ApiInfo apiInfo () {

String version = DateUtil.customFormat (new Date (), "yyyyMMdd.HHmmss")

Return new ApiInfoBuilder ()

.title ("Onstand classroom (Business Edition)")

Description ("Enli classroom second edition, upgraded business modules on SDK version, business modules include: users, teachers, students, courses, classes, class statistics, etc.")

.version ("v2." + version)

.license ("Apache License Version 2.0")

.licenseUrl ("https://www.apache.org/licenses/LICENSE-2.0")"

.contact (new Contact ("Zhu Zengliang", "zhuzengliang@onlyedu.com"))

.build ()

}

}

Visit

Default access path http://locahost:8080/swagger.html

Knife4j dependency package compile group: 'com.github.xiaoymin', name:' knife4j-spring-boot-starter', version: '2.0.4'

Configuration

Add comments to the original SwaggerConfig class:

@ EnableKnife4j

@ Import (BeanValidatorPluginsConfiguration.class)

Visit

Default access path http://locahost:8080/doc.html

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Servers

Wechat

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

12
Report