Api

  用在Controller中,标记一个Controller作为swagger的文档资源

属性名称 说明

value

Controller的注解
description 对api资源的描述
hidden 配置为true 将在文档中隐藏

使用方法:

 @Api(value = "登录服务",description = "用户登录相关接口")
@RestController("loginControllerLayui")
@RequestMapping("/login")
public class LoginController {
}

ApiOperation

  该注解用在Controller的方法中,用于注解接口

属性名称 说明
value 接口的名称
notes 接口的注释
response 接口的返回类型,比如说:response = String.class
hidden 配置为true 将在文档中隐藏

使用方法:

@ApiOperation(value = "获取验证码图片",notes = "每调用一次,就会随机生成一张验证码图片",response = String.class)
@GetMapping("/verifyCode.img")
public String getVerifyCode(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
}

ApiParam

  该注解用在方法的参数中。

属性名称 说明
name 参数名称
value 参数值
required 是否必须,默认false
defaultValue 参数默认值
type 参数类型
hidden 隐藏该参数

 

使用方法:

@ApiOperation(value = "添加权限",notes = "插入权限",response = JsonData.class)
@PostMapping("/insertAcl.json")
public JsonData insertAcl(@ApiParam(name = "param",value = "实体类AclParam",required = true) AclParam param){
}

ApiResponses/ApiResponse

  该注解用在Controller的方法中,用于注解方法的返回状态。

属性名称 说明
code http的状态码
message 状态的描述信息
response 状态相应,默认响应类 Void

  

使用方法:

@ApiOperation(value = "菜单",notes = "进入菜单界面",nickname = "菜单界面")
@ApiResponses({
@ApiResponse(code = 200,message = "成功!"),
@ApiResponse(code = 401,message = "未授权!"),
@ApiResponse(code = 404,message = "页面未找到!"),
@ApiResponse(code = 403,message = "出错了!")
})
@GetMapping("/aclModule.page")
public ModelAndView aclModule(Model model){
}

ApiModel

  该注解用在实体类中。

属性名称 说明
value 实体类名称
description 实体类描述
parent 集成的父类,默认为Void.class
subTypes 子类,默认为{}
reference 依赖,默认为“”

  

使用方法:

@ApiModel(value = "JsonData",description = "返回的数据类型")
public class JsonData {
}

ApiImplicitParams/ApiImplicitParam

  该注解用在Controller的方法中,同ApiParam的作用相同,但是比较建议使用ApiParam。

属性名称 说明
name 参数名称
value 参数值
defaultValue 参数默认值
required 是否必须
allowMultiple 是否允许重复
dataType 数据类型
paramType 参数类型

  

使用方法:

@ApiOperation(value = "创建用户",notes = "根据User对象创建用户")
@ApiImplicitParam(name = "user",value = "用户详细实体user")
@RequestMapping(value="/", method=RequestMethod.POST)
public String postUser(@ModelAttribute User user){
}

ApiModelProperty

  该注解用在实体类的字段中。

属性名称 说明
name 属性名称
value 属性值
notes 属性注释
dataType 数据类型,默认为“”
required 是否必须,默认为false
hidden 是否隐藏该字段,默认为false
readOnly 是否只读,默认false
reference 依赖,,默认“”
allowEmptyValue 是否允许空值,默认为false
allowableValues 允许值,默认为“”

使用方法:

//返回状态信息
@ApiModelProperty(name = "code",value = "状态code",notes = "返回信息的状态")
private int code;
//返回携带的信息内容
@ApiModelProperty(name = "msg",value = "状态信息",notes = "返回信息的内容")
private String msg = "";
//返回信息的总条数
@ApiModelProperty(name = "count",value = "查询数量",notes = "返回信息的条数")
private int count;
//返回对象
@ApiModelProperty(name = "data",value = "查询数据",notes = "返回数据的内容")
private Object data;

Swagger2常用注解及其说明 (转)的更多相关文章

  1. swagger2常用注解

    常用注解: @Api()用于类: 表示标识这个类是swagger的资源 @ApiOperation()用于方法: 表示一个http请求的操作 @ApiParam()用于方法,参数,字段说明: 表示对参 ...

  2. Swagger2常用注解和使用方法

    一   引入maven依赖 <!--整合Swagger2--> <dependency> <groupId>com.spring4all</groupId&g ...

  3. Swagger2常用注解解析(轻松构建Swagger)

    Swagger2常用注解解析 一.SpringBoot集成Swagger2 二.常用注解解析 具体使用举例说明: 一.SpringBoot集成Swagger2 引入相关jar包 <!-- swa ...

  4. swagger2常用注解说明

    说明: 1.这里使用的版本:springfox-swagger2(2.4)springfox-swagger-ui (2.4) 2.这里是说明常用注解的含义和基本用法(也就是说已经对swagger进行 ...

  5. swagger2 常用注解的使用

    一.@Api 效果: @Api注解放在类上面,这里的value是没用的,tags表示该controller的介绍. 二 .@ApiOperation 效果: @ApiOperation注解用于放在方法 ...

  6. swagger2 常用注解说明

    常用到的注解有: Api ApiModel ApiModelProperty ApiOperation ApiParam ApiResponse ApiResponses ResponseHeader ...

  7. Swagger2:常用注解说明

    Swagger2常用注解说明 Spring Boot : Swagger 2使用教程:https://www.cnblogs.com/JealousGirl/p/swagger.html 这里只讲述@ ...

  8. swagger2的常用注解,传递参数的注意使用方法

    背景介绍: 刚开始的时候,在controller层使用@RequestParam的时候,发现这个参数是必须要输入值的,但是我们有时候必须查询的时候允许参数为空,使用这个注解就不行了. 在集成了swag ...

  9. Spring系列之Spring常用注解总结

    传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...

随机推荐

  1. jenkins中布置python测试

    测试代码 #coding:utf- import unittest class MyTest(unittest.TestCase): # 继承unittest.TestCase def tearDow ...

  2. iframe 加载闪过白块问题

    每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 在使用iframe时,iframe背景为白块,刷新时也会闪过白块.如果刷新时间长,就会 ...

  3. tomcat 改端口 运维最最重要的就是有看日志的习惯

    tomcat一台机器上多实例更改端口需要改三个端口 改tomcat关闭端口 <Server port="9006" shutdown="SHUTDOWN" ...

  4. 理解 vue-router的beforeEach无限循环的问题

    在理解beforeEach无限循环之前,我们先来看一下beforeEach相关的知识点,该篇文章的项目是基于 express+vue+mongodb+session实现注册登录 这篇文章项目基础之上进 ...

  5. LOJ6036 编码 2-SAT、Trie

    传送门 每个串只有一个?,?还只能填0或者1,不难想到2-SAT求解. 一个很暴力的想法是枚举?填0或者1,然后对所有可能的前缀连边.这样边数是\(O(n^2)\)的,需要优化. 看到前缀不难想到Tr ...

  6. 抽取非基本验证到规则文件 - A2D规则引擎

    基本验证与业务验证,基本验证就是始终保持不变的验证规则,可以通过如下硬编码实现: public class Order { [Required] [Range(")] public deci ...

  7. 《Spring Boot 入门及前后端分离项目实践》系列介绍

    课程计划 课程地址点这里 本课程是一个 Spring Boot 技术栈的实战类课程,课程共分为 3 个部分,前面两个部分为基础环境准备和相关概念介绍,第三个部分是 Spring Boot 项目实践开发 ...

  8. Jenkins- job之间传参

    前言: 本文介绍插件: Parameterized Trigger plugin的具体使用方法. 一.插件介绍 Parameterized Trigger plugin插件可以让你在构建完成时触发新的 ...

  9. Dijkstra的应用

    每次只涉及一边两端点的极值循环转移应用Dijkstra.

  10. Yii1.1框架关于日志的配置的简单使用

    最近开始接触新项目,新项目用的框架是Yii1.1版本的,通过看框架文档大致熟悉了解了Yii在日志方面的使用. 首先在protected/config/main.php配置文件中加入日志相关配置,如下图 ...