SpringBoot在整合swagger2中常用注解,更方便的使用和阅读文档

本文详细介绍SpringBoot项目中如何集成Swagger2实现API文档自动生成。包括如何在控制器上使用@Api、@ApiOperation等注解来描述接口作用及请求方式,以及如何通过@ApiModel和@ApiModelProperty注解对接口参数进行描述。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

springboot整合swagger2的方法请阅读 

Spring boot 整合swagger2的步骤

一、controller上使用

@Api(value = "注册登陆",tags = {"用于登陆的相关接口"})

类名上的备注,主要用于展示整个类接口的分组描述。

@ApiIgnore

忽略生成api

@ApiOperation(value = "用户注册",notes = "用户注册",httpMethod = "POST")

方法上描述,该接口的左右及请求方式

@ApiModel(value = "用户注册对象",description = "客服端传来的数据封装")
@DATA
public class UserBO {
    @ApiModelProperty(value = "用户名",name="username",example = "admin",required = true)
    private String username;
    @ApiModelProperty(value = "密码",name="password",example = "123456",required = true)
    private String password;
    @ApiModelProperty(value = "确认密码",name="confirmPassword",example = "123456",required = true)
    private String confirmPassword;
}

接口参数封装类上的描述

 

整体效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值