Swagger的使用笔记

1、首先配置Swagger的jar包

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

 

2、设置Swagger的配置文件

@Configuration
@EnableSwagger2
public class SwaggerConfig {

}

3、访问http://localhost:8080/swagger-ui.html

 

 4、配置Swagger页面信息

@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//RequestHandlerSelectors配置扫描包的方式
//basePackage: 指定要扫描的包
//any扫描全部
.apis(RequestHandlerSelectors.basePackage("com.liukx.springboot_vue.controller"))
.build()
.groupName("分组1") //分组
.enable(true); //配置运行项目是否启用Swagger
}
private ApiInfo apiInfo(){
//作者信息
Contact contact = new Contact("刘恺翔", "https://www.baidu.com", "757977299@qq.com");

return new ApiInfo("恺翔的Swagger的API文档",
"命若天定,我便破了这个天!",
"v1.0",
"https://www.baidu.com",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList());
}
posted @   恺翔  阅读(36)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
点击右上角即可分享
微信分享提示