当前位置:网站首页>Swagger前后台集成工具
Swagger前后台集成工具
2022-08-07 05:14:00 【Shawn的代码日常】
Swagger的使用方法
1.引入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
2.配置Swagger2
@Configuration
@EnableSwagger2
//3.0.0以上版本无需加该注解
public class Swagger2Configuration{
@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("用户管理系统")
.description("用户管理系统接口文档")
.version("3.3")
.contact(new Contact("公司名","http://www.baidu.com","[email protected]"))
.build()
)
.select()
//Controller所在的包
.api(RequestHandlerSelectors.basePackage("com.xxx.controller"))
.build();
}
}
3.访问API文档页面
在浏览器中访问 http://localhost:8080/projectName/swagger-ui/index.html 即可。
4.常用注解
实例写一个Controller类
@RestController
@RequestMapping("/user")
@Api(tags="用户相关操作接口")
public class UserController{
@ApiOperation("根据用户Id进行查询")
@ApiImplicitParam(name="id",value="用户id",requires=true,example="33",defaultValue="444")
@PostMapping("/selectById")
public String selectById(Integer id){
...
return "selectById";
}
}
如果传参是一个实体类对象User,栗子:
@ApiModel
public class User{
//对Integer等数字类型需要赋默认值,否则报错
@ApiModelProperty(value="用户ID",example="1")
private Integer userId;
@ApiModelProperty(value="用户名")
private String userName;
@ApiModelProperty(value="用户密码")
private String password;
@ApiModelProperty(value="用户地址")
private String address;
...(setter,getter and toString)
}
提取知识点:
@Api:用于设置模块接口名
@ApiOperation(...):用于设置功能方法名
@ApiImplicitParam:用于描述方法参数含义其下一些参数描述:
①name:形参名
②value:描述含义
③required:是否为必填项
④example:样例值
⑤defaultValue:默认值
@ApiImplicitParams:使用数组格式存储多个参数描述
@ApiModel:用在实体类上,用于实体类在API文档上的说明。
@ApiModelProperty:用于说明实体类中属性在API文档上的解释说明。
边栏推荐
猜你喜欢

DGIOT国内首家轻量级物联网开源平台——一键式部署TLS证书

dcdc低压升压直流稳压高压负电压输出12v24v转-50V100V110V150V200V250V300V350V400V500V

DCDC DC low voltage step-up voltage isolation power module (with short circuit protection)

AD封装库的下载与导入

SCCB协议

基于STC8G2K64S4单片机控制直流电机

回溯 -- 21天学习挑战赛第一天

PCB封装库网站

AD封装库的免费下载与导入

DGIOT device configuration synchronously sends control commands
随机推荐
智能机器人制作全攻略
华为云部署
DGIoT task scheduling
DGIoT编程规范
入坑大学时光、单片机开发,嵌入式网站推荐
远程定位
DGIOT国内首家轻量级物联网开源平台——支持多型太阳能板远程管控和多屏运维
【无标题】迁移学习(Transfer Learning)核心技术开发与应用
abstract(抽象类)与interface(接口)的区别
自定义IP核——AXI4接口
直接插入排序
【题解报告】 -- 2327. 知道秘密的人数
【Unity】消息协议的设计
I2C协议
两数相乘:但是不用*号。如何不用*符号的两数相乘
MySQL索引失效的10个场景(详细测试)
YL70 远程I/O模块,可以用来测量四路开关量信号,并有四路继电器信号输出
STM32按键输入实验
DGIOT IoT Open Source Platform - Tencent Cloud Lightweight Application Server Deployment
Xcode13.1真机调试