swagger2常用注解说明
说明: 
1.这里使用的版本:springfox-swagger2(2.4)springfox-swagger-ui (2.4) 
2.这里是说明常用注解的含义和基本用法(也就是说已经对swagger进行集成完成) 
没有集成的请参见 
SpringBoot集成springfox-swagger2构建restful API 
SpringMVC集成springfox-swagger2构建restful API 
官网WIKI 
常用注解: 
- @Api()用于类; 
表示标识这个类是swagger的资源 
- @ApiOperation()用于方法; 
表示一个http请求的操作 
- @ApiParam()用于方法,参数,字段说明; 
表示对参数的添加元数据(说明或是否必填等) 
- @ApiModel()用于类 
表示对类进行说明,用于参数用实体类接收 
- @ApiModelProperty()用于方法,字段 
表示对model属性的说明或者数据操作更改 
- @ApiIgnore()用于类,方法,方法参数 
表示这个方法或者类被忽略 
- @ApiImplicitParam() 用于方法 
表示单独的请求参数 
- @ApiImplicitParams() 用于方法,包含多个 @ApiImplicitParam
具体使用举例说明: 
@Api() 
用于类;表示标识这个类是swagger的资源 
tags–表示说明 
value–也是说明,可以使用tags替代 
但是tags如果有多个值,会生成多个list
@Api(value="用户controller",tags={"用户操作接口"})
@RestController
public class UserController {
}- 1
- 2
- 3
- 4
- 5
效果图: 
@ApiOperation() 用于方法;表示一个http请求的操作 
value用于方法描述 
notes用于提示内容 
tags可以重新分组(视情况而用) 
@ApiParam() 用于方法,参数,字段说明;表示对参数的添加元数据(说明或是否必填等) 
name–参数名 
value–参数说明 
required–是否必填
@Api(value="用户controller",tags={"用户操作接口"})
@RestController
public class UserController {
     @ApiOperation(value="获取用户信息",tags={"获取用户信息copy"},notes="注意问题点")
     @GetMapping("/getUserInfo")
     public User getUserInfo(@ApiParam(name="id",value="用户id",required=true) Long id,@ApiParam(name="username",value="用户名") String username) {
     // userService可忽略,是业务逻辑
      User user = userService.getUserInfo();
      return user;
  }
}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
效果图: 
@ApiModel()用于类 ;表示对类进行说明,用于参数用实体类接收 
value–表示对象名 
description–描述 
都可省略 
@ApiModelProperty()用于方法,字段; 表示对model属性的说明或者数据操作更改 
value–字段说明 
name–重写属性名字 
dataType–重写属性类型 
required–是否必填 
example–举例说明 
hidden–隐藏
@ApiModel(value="user对象",description="用户对象user")
public class User implements Serializable{
    private static final long serialVersionUID = 1L;
     @ApiModelProperty(value="用户名",name="username",example="xingguo")
     private String username;
     @ApiModelProperty(value="状态",name="state",required=true)
      private Integer state;
      private String password;
      private String nickName;
      private Integer isDeleted;
      @ApiModelProperty(value="id数组",hidden=true)
      private String[] ids;
      private List<String> idList;
     //省略get/set
}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
  @ApiOperation("更改用户信息")
  @PostMapping("/updateUserInfo")
  public int updateUserInfo(@RequestBody @ApiParam(name="用户对象",value="传入json格式",required=true) User user){
     int num = userService.updateUserInfo(user);
     return num;
  }- 1
- 2
- 3
- 4
- 5
- 6
- 7
效果图: 
@ApiIgnore()用于类或者方法上,可以不被swagger显示在页面上 
比较简单, 这里不做举例
@ApiImplicitParam() 用于方法 
表示单独的请求参数 
@ApiImplicitParams() 用于方法,包含多个 @ApiImplicitParam 
name–参数ming 
value–参数说明 
dataType–数据类型 
paramType–参数类型 
example–举例说明
  @ApiOperation("查询测试")
  @GetMapping("select")
  //@ApiImplicitParam(name="name",value="用户名",dataType="String", paramType = "query")
  @ApiImplicitParams({
  @ApiImplicitParam(name="name",value="用户名",dataType="string", paramType = "query",example="xingguo"),
  @ApiImplicitParam(name="id",value="用户id",dataType="long", paramType = "query")})
  public void select(){
  }- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
效果图: 
swagger2常用注解说明的更多相关文章
- swagger2常用注解
		常用注解: @Api()用于类: 表示标识这个类是swagger的资源 @ApiOperation()用于方法: 表示一个http请求的操作 @ApiParam()用于方法,参数,字段说明: 表示对参 ... 
- Swagger2常用注解和使用方法
		一 引入maven依赖 <!--整合Swagger2--> <dependency> <groupId>com.spring4all</groupId&g ... 
- Swagger2常用注解解析(轻松构建Swagger)
		Swagger2常用注解解析 一.SpringBoot集成Swagger2 二.常用注解解析 具体使用举例说明: 一.SpringBoot集成Swagger2 引入相关jar包 <!-- swa ... 
- swagger2 常用注解的使用
		一.@Api 效果: @Api注解放在类上面,这里的value是没用的,tags表示该controller的介绍. 二 .@ApiOperation 效果: @ApiOperation注解用于放在方法 ... 
- swagger2 常用注解说明
		常用到的注解有: Api ApiModel ApiModelProperty ApiOperation ApiParam ApiResponse ApiResponses ResponseHeader ... 
- Swagger2常用注解及其说明 (转)
		Api 用在Controller中,标记一个Controller作为swagger的文档资源 属性名称 说明 value Controller的注解 description 对api资源的描述 hid ... 
- Swagger2:常用注解说明
		Swagger2常用注解说明 Spring Boot : Swagger 2使用教程:https://www.cnblogs.com/JealousGirl/p/swagger.html 这里只讲述@ ... 
- swagger2的常用注解,传递参数的注意使用方法
		背景介绍: 刚开始的时候,在controller层使用@RequestParam的时候,发现这个参数是必须要输入值的,但是我们有时候必须查询的时候允许参数为空,使用这个注解就不行了. 在集成了swag ... 
- Spring系列之Spring常用注解总结
		传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ... 
随机推荐
- Xml的转义字符--约束-xml解析器
			XML解析器:Dom适合增删改查(crud),缺点就是内存消耗大: Sax:内存消耗非常小,解析速度快,但是不适合增删改: 
- python-----短信、电话告警
			Twilio 1.访问http://twilio.com/并注册.注册了新账户后,你需要验证一个手机号码,短信将发给该号码. 2.Twilio 提供的试用账户包括一个电话号码,它将作为短信的发送者.你 ... 
- vim7.4+python3配置
			基本参考:https://blog.csdn.net/qq_26877377/article/details/80717755 注意几点: (1)关于python的自动补全,不要使用pydiction ... 
- Linux内核很吊之 module_init解析 (下)【转】
			转自:https://blog.csdn.net/richard_liujh/article/details/46758073 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ... 
- 004_zookeeper运维之maxClientCnxns overflow
			一. 线上默认设置:maxClientCnxns=120 #可通过修改这个值来进行解决 二. 在10.103.110.51这个ip上执行以下命令,进行查看连接情况 [root@10.103.101 ... 
- 基于Hadoop2.7.3集群数据仓库Hive1.2.2的部署及使用
			基于Hadoop2.7.3集群数据仓库Hive1.2.2的部署及使用 HBase是一种分布式.面向列的NoSQL数据库,基于HDFS存储,以表的形式存储数据,表由行和列组成,列划分到列族中.HBase ... 
- Golang channel 特性
			最近在项目中遇到了 Go channel 的一些问题,在此记录下 close channel 的一些特性. 关闭channel ch := make(chan bool) close(ch) clos ... 
- mysql 命令行常用命令
			1.显示数据库列表. show databases; 2.显示库中的数据表: use mysql; show tables; 3.显示数据表的结构: describe 表名; 4.建库: cr ... 
- android开机动画(bootanimation)
			Android开机动画有两种修改方法,android 2.0及之后,使用bootanimation程序显示开机画面,如需修改开机画面,不用修改代码,只需按格式要求做bootanimation.zip包 ... 
- nginx的location、rewrite玩法详解
			1. location正则写法 一个示例: 1234567891011121314151617181920212223242526272829303132333435363738394041424 ... 
