SpringBoot开启Swagger并配置基本信息方式
作者:yui方木
这篇文章主要介绍了SpringBoot开启Swagger并配置基本信息方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
前后端分离:前后端交互:API
前后端集成联调,前后端人员无法及时协商
解决方案
- 首先制定schema[计划的提纲],实时更新最新API,降低集成风险
- Swagger
Swagger
- 世界上最流行的API框架
- Restful API 文档在线自动生成工具–>API文档与API定义同步更新
- 可以在线直接运行,直接测试
- 支持多种语言:Java、PHP…
在项目中使用swagger:springfox
- swagger2
- ui
Springboot集成Swagger
导包:
<!-- swagger --> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <!-- swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency>
配置swagger:
package com.example.config;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
/**开启Swagger2*/
@EnableSwagger2
public class SwaggerConfig {
}
然后就可以访问swagger页面:
/swagger-ui.html

配置swagger
进ApiInfo这个类看看,有什么Api配置属性:


SwaggerConfig配置类:
配置ApiInfo:
@Configuration
/*开启Swagger2*/
@EnableSwagger2 /* :/swagger-ui.html */
public class SwaggerConfig {
//配置Swagger的Docket的bean实例
@Bean
public Docket docket(){
//配置文档信息
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
}
//配置apiinfo
private ApiInfo apiInfo(){
//作者信息
Contact contact = new Contact("fzl","https://blog.csdn.net/weixin_44976835","1403275028@qq.com");
return new ApiInfo(
"Epidemic Swagger",
"fzl最帅",
"1.0",
"https://blog.csdn.net/weixin_44976835",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList()
);
}
}
可以配置swagger-ui.html页面信息,配置完变成了:

没什么大用,就是更改一个文档说明,还能标注个作者什么的^ .^
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
