当前位置:网站首页>在线教育项目整合Swagger
在线教育项目整合Swagger
2022-07-20 08:29:00 【Fairy要carry】
项目结构:
所需依赖
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<scope>provided </scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<scope>provided </scope>
</dependency>
文档配置
package com.atguigu.eduservice;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
/**
* 文档配置
* @return
*/
@Bean
public Docket webApiConfig(){
return new Docket(DocumentationType.SWAGGER_2)
//表示分组组名
.groupName("webApi")
//设置文档的信息
.apiInfo(webApiInfo())
.select()
//该路径下接口不显示
.paths(Predicates.not(PathSelectors.regex("/admin/.*")))
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}
/**
* 文档信息
* @return
*/
private ApiInfo webApiInfo(){
return new ApiInfoBuilder()
.title("网站-课程中心API文档")
.description("本文档描述了课程中心微服务接口定义")
.version("1.0")
.contact(new Contact("Helen", "http://atguigu.com", "[email protected]"))
.build();
}
}
然后其他模块引入这个模块即可
<dependency>
<groupId>com.atguigu</groupId>
<artifactId>service-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
注意在其他调用模块上的启动类需要加注解
API模型例子
定义在类上:@Api
定义在方法上:@ApiOperation
定义在参数上:@ApiParam
@Api(description = "讲师管理")
@RestController
@CrossOrigin
@RequestMapping("/eduservice/teacher")
public class EduTeacherController {
@Autowired
private EduTeacherService teacherService;
/**
* 1.查询教师表中所有数据
* SELECT id,name,intro,career,level,avatar,sort,is_deleted,gmt_create,gmt_modified FROM edu_teacher WHERE is_deleted=0
*/
@ApiOperation(value = "所有讲师")
@GetMapping("findAll")
public R findAllTeacher() {
List<EduTeacher> list = teacherService.list(null);
return R.ok().data("items", list);
}
@ApiModelProperty(value = "创建时间", example = "2019-01-01 8:00:00")
@TableField(fill = FieldFill.INSERT)
private Date gmtCreate;
@ApiModelProperty(value = "更新时间", example = "2019-01-01 8:00:00")
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date gmtModified;
边栏推荐
- redis 'module' 不是内部或外部命令?
- Getting started with microservices
- CAD完美转ArcGIS的操作方法技巧
- php得到网站根目录,php获得网站根目录的几个方法
- php 匹配正则 取出url
- Object.defineProperty使用
- In the second quarter of 2022, Web3 became the most interesting area for encryption venture capital
- ASP. Net core using redis
- 「接口测试入门课」打卡学习 day09:微服务接口:怎么用Mock解决混乱的调用关系
- Webdynpro development-03 create a Webdynpro material code query page
猜你喜欢
VOD constructs its own player, and the user calls the interface to obtain the video playback address
Spark高效数据分析04、RRD创建
ASP. Net core using Autofac
R 语言 rmd输出有中文 ,怎么去除中文
数字孪生落地设计桥梁可视化解决方案
【Pygame实战】怀旧经典—这款给娃的棋类游戏,你还记得叫什么吧?(一定要收藏)
TP5.1 登录 配置是否登录公共函数的方法(完整的登录案例)
字节跳动(抖音)软件测试月薪23K岗、技术总监三面面试题最新出炉
LeetCode-24-两两交换链表中的节点
In the second quarter of 2022, Web3 became the most interesting area for encryption venture capital
随机推荐
R语言世界价值观调查作业
如何使用Blender制作360度全景图和全景视频?
Common classes under JUC package
R language world values survey assignment
Go atomic operation
点播 构造自己的播放器 用户调用获取视频播放地址接口
Php obtient le Répertoire racine du site Web, plusieurs méthodes PHP obtient le Répertoire racine du site Web
渗透测试-SQL注入之sqlmap的使用方法及实战案例
mp4封装解析
R language data analysis and statistical software application unit 1 exercise (code and result documents are required to be submitted)
Regular expression matching URL
使用R从Excel中删除带有空单元格的行
C#入门系列(二十五) -- 接口
Cloud Foundry 开发 4.cf 命令
多线程理论基础
CTFShow-MISC入门篇
Webdynpro development-03 create a Webdynpro material code query page
Object.defineProperty使用
工业4.0数字孪生下的应用案例
IT7259Q-13、IT7259EX-24特征 可穿戴设备