## 接口响应消息体

/***      Copyright (c) 2018-2025, lengleng All rights reserved.**  Redistribution and use in source and binary forms, with or without*  modification, are permitted provided that the following conditions are met:** Redistributions of source code must retain the above copyright notice,*  this list of conditions and the following disclaimer.*  Redistributions in binary form must reproduce the above copyright*  notice, this list of conditions and the following disclaimer in the*  documentation and/or other materials provided with the distribution.*  Neither the name of the hzcloud.com developer nor the names of its*  contributors may be used to endorse or promote products derived from*  this software without specific prior written permission.*  Author: lengleng (wangiegie@gmail.com)**/package com.hzcloud.hz.common.core.util;import com.hzcloud.hz.common.core.constant.CommonConstants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;import java.io.Serializable;/*** 响应信息主体** @param <T>* @author lengleng*/
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ApiModel(value = "响应信息主体")
public class R<T> implements Serializable {private static final long serialVersionUID = 1L;@Getter@Setter@ApiModelProperty(value = "返回标记:成功标记=0,失败标记=1")private int code;@Getter@Setter@ApiModelProperty(value = "返回信息")private String msg;@Getter@Setter@ApiModelProperty(value = "数据")private T data;public static <T> R<T> ok() {return restResult(null, CommonConstants.SUCCESS, null);}public static <T> R<T> ok(T data) {return restResult(data, CommonConstants.SUCCESS, null);}public static <T> R<T> ok(T data, String msg) {return restResult(data, CommonConstants.SUCCESS, msg);}public static <T> R<T> failed() {return restResult(null, CommonConstants.FAIL, null);}public static <T> R<T> failed(String msg) {return restResult(null, CommonConstants.FAIL, msg);}public static <T> R<T> failed(T data) {return restResult(data, CommonConstants.FAIL, null);}public static <T> R<T> failed(T data, String msg) {return restResult(data, CommonConstants.FAIL, msg);}private static <T> R<T> restResult(T data, int code, String msg) {R<T> apiResult = new R<>();apiResult.setCode(code);apiResult.setData(data);apiResult.setMsg(msg);return apiResult;}
}

## 使用:在接口返回值后加上类的名称

#如下返回值为 R 这个Integer就是类型名称

/*** 查询未完成的场次的数量* @return 未完成的场次的数量*/@GetMapping("/queryUnfinishedImplementationCount")@ApiOperation(value = "查询未完成的场次的数量", notes = "查询未完成的场次的数量")public R<Integer> getById() {QueryWrapper<FlightplanSet> flightplanSetQueryWrapper=new QueryWrapper<>();flightplanSetQueryWrapper.eq("implementation_status",Constants.FLIGHT_PLAN_SET_IMPLEMENTATION_STATUS_OF_UNFINISHED);flightplanSetQueryWrapper.eq("del_flag",Constants.DEL_FLAG_NORMAL);return R.ok(flightplanSetService.count(flightplanSetQueryWrapper));}

结果,swagger就会生成带有返回结构的响应体

Swagger2 生成API文档时泛型总是显示不出来的问题相关推荐

  1. SpringBoot2.x整合Swagger2 实现API文档实时生成

    我们提供Restful接口的时候,API文档是尤为的重要,它承载着对接口的定义,描述等,本文主要介绍了SpringBoot集成Swagger2生成接口文档的方法示例,需要的朋友们下面随着小编来一起学习 ...

  2. 为TypeScript项目生成API文档

    为TypeScript项目生成文档 使用typedoc为TypeScript项目生成API文档. 1. 使用typedoc生成HTML文档 需要安装 typedoc. npm i typedoc 可以 ...

  3. 干掉 Postman?测试接口直接生成API文档,这工具真香!

    前几天粉丝群有小伙伴问,有啥好用的API文档工具推荐,无意间发现了一款工具,这里马不停蹄的来给大家分享一下. ShowDoc一个非常适合团队的在线API文档工具,也支持用docker自建文档服务,不过 ...

  4. 干掉 Postman?测试接口直接生成API文档,这个工具我爱了

    前几天粉丝群有小伙伴问,有啥好用的API文档工具推荐,无意间发现了一款工具,这里马不停蹄的来给大家分享一下. ShowDoc一个非常适合团队的在线API文档工具,也支持用docker自建文档服务,不过 ...

  5. springboot 集成 swagger 自动生成API文档

    Swagger是一个规范和完整的框架,用于生成.描述.调用和可视化RESTful风格的Web服务.简单来说,Swagger是一个功能强大的接口管理工具,并且提供了多种编程语言的前后端分离解决方案. S ...

  6. knife4j是为Java MVC框架集成Swagger生成Api文档的增强解决方案

    knife4j knife4j是为Java MVC框架集成Swagger生成Api文档的增强解决方案,前身是swagger-bootstrap-ui,取名kni4j是希望它能像一把匕首一样小巧,轻量, ...

  7. 【接口文档】Django restful framework中自动生成API文档

    Django restful framework中自动生成API文档 一.Swagger概述 1.引言 当接口开发完成,紧接着需要编写接口文档.传统的接口文档使用Word编写,or一些接口文档管理平台 ...

  8. 浅析如何在Nancy中使用Swagger生成API文档

    原文:浅析如何在Nancy中使用Swagger生成API文档 前言 上一篇博客介绍了使用Nancy框架内部的方法来创建了一个简单到不能再简单的Document.但是还有许许多多的不足. 为了能稍微完善 ...

  9. 干掉 Swagger + Postman?测试接口直接生成API文档,这个国产文档工具真香!

    点击上方"芋道源码",选择"设为星标" 管她前浪,还是后浪? 能浪的浪,才是好浪! 每天 10:33 更新文章,每天掉亿点点头发... 源码精品专栏 原创 | ...

最新文章

  1. arraylist 后往前遍历_面试官:谈谈常用的Arraylist和Linkedlist的区别
  2. 没有人能够解释为什么飞机可以待在空中
  3. 关于软件外包的一些看法(转)
  4. 一个简单自激振荡器电路分析
  5. loader调用过程
  6. 【图像超分辨率】基于ResNet或GAN的遥感图像超分辨率论文
  7. 二隐层的神经网络实现MNIST数据集分类
  8. kali里PHP文件502错误,解决Linux Kali iptables开放22端口失败等一系列问题
  9. Object-C-NSFileManager
  10. 三坐标测量圆直径_多台三坐标测量机联动测量方法的研究
  11. 绝对不能错过!计算机视觉Polygon Mesh Processing读书笔记——4微分几何中的曲线
  12. (转)嵌入式按键驱动,支持短按、长按、双击(中断方式)
  13. web 开发 —— html 与 css(div)
  14. stm32,51单片机,AVR单片机( arduino )到底选哪个比较好
  15. KMP算法 next数组 nextval数组
  16. vmrc必须从URL启动该应用程序
  17. QQ音乐歌曲解析API接口
  18. Fastadmin读取数据库配置
  19. 计算机多余自动启动项,大神教你WIN7如何删除多余系统启动项
  20. 计算机开机时前按什么键,开机怎么进入bios?电脑开机按什么键进入BIOS方法大全...

热门文章

  1. html 选择自动增加行数,HTML怎么自动计算出上两行的值在第三行里面?
  2. 扫掠曲面二条引导线_说说国策下的三四线城市与会展
  3. android伸缩动画自定义,Android干货:自定义带动画的View
  4. 20181031-1
  5. 韩山师范计算机应用技术,二、计算机应用与技术系学生在韩山师范学院“挑战杯”的-….pdf...
  6. mysql行格式_MySQL 行格式
  7. 接口安全怎么处理_压瓦机设备噪声大怎么处理及压瓦机的安全使用
  8. 世界上最漂亮的写作工具Typora(创作者必备软件)
  9. @ConfigurationProperties 在IDEA中出现红色波浪线问题
  10. c#执行多句oracle,C#一次执行多条SQL语句,Oracle11g数据库