swagger去掉请求体中多余参数同时显示完整返回实体各个字段标注的方法

  • 控制器
@ApiOperation(value = "教学视频上传接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "videoName", value = "视频名")
    })
    @PostMapping("/video")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = EcVideo.class)
    })

    public ServerResponse upload(@ApiIgnore @RequestBody EcVideoDTO ecVideoDTO
            ) throws Exception {
        return videoService.upload(ecVideoDTO);
    }
  • 控制器response对象
package cn.hctech2006.excellentcourse.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@ApiModel(value ="ecVideo" ,description = "教学视频模型")
@Data

public class EcVideo implements Serializable {
    @ApiModelProperty(hidden = true)
    private Integer id;
    @ApiModelProperty(name = "videoId", value = "教学视频唯一标识")
    private String videoId;
    @ApiModelProperty(name = "videoName", value = "教学视频名称")
    private String videoName;
    @ApiModelProperty(name = "videoUrl", value = "教学视频地址")
    private String videoUrl;
    @ApiModelProperty(name = "videoImgUrl", value = "业务视频截图地址" )
    private String videoImgUrl;
    @ApiModelProperty(name = "videoIntro", value = "业务视频介绍")
    private String videoIntro;
    @ApiModelProperty(name = "videoTime", value = "视频上传时间")
    private Date videoTime;
    @ApiModelProperty(name = "viewTimes", value = "视频浏览次数")
    private Integer viewTimes;
    @ApiModelProperty(name = "showFlag", value = "视频是否可以显示")
    private String showFlag;
    @ApiModelProperty(name = "showSort", value = "列表显示排序, 1-正无穷")
    private int showSort;

    private static final long serialVersionUID = 1L;

    public String getShowFlag() {
        return showFlag;
    }

    public void setShowFlag(String showFlag) {
        this.showFlag = showFlag;
    }

    public int getShowSort() {
        return showSort;
    }

    public void setShowSort(int showSort) {
        this.showSort = showSort;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getVideoId() {
        return videoId;
    }

    public void setVideoId(String videoId) {
        this.videoId = videoId;
    }

    public String getVideoName() {
        return videoName;
    }

    public void setVideoName(String videoName) {
        this.videoName = videoName;
    }

    public String getVideoUrl() {
        return videoUrl;
    }

    public void setVideoUrl(String videoUrl) {
        this.videoUrl = videoUrl;
    }

    public String getVideoImgUrl() {
        return videoImgUrl;
    }

    public void setVideoImgUrl(String videoImgUrl) {
        this.videoImgUrl = videoImgUrl;
    }

    public String getVideoIntro() {
        return videoIntro;
    }

    public void setVideoIntro(String videoIntro) {
        this.videoIntro = videoIntro;
    }

    public Date getVideoTime() {
        return videoTime;
    }

    public void setVideoTime(Date videoTime) {
        this.videoTime = videoTime;
    }

    public Integer getViewTimes() {
        return viewTimes;
    }

    public void setViewTimes(Integer viewTimes) {
        this.viewTimes = viewTimes;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", videoId=").append(videoId);
        sb.append(", videoName=").append(videoName);
        sb.append(", videoUrl=").append(videoUrl);
        sb.append(", videoImgUrl=").append(videoImgUrl);
        sb.append(", videoIntro=").append(videoIntro);
        sb.append(", videoTime=").append(videoTime);
        sb.append(", viewTimes=").append(viewTimes);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}
  • 控制器数据传输对象DTO
package dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(description = "教学视频模型")
public class VideoDTO {
    @ApiModelProperty(name = "videoName", value = "教学视频名", required = true)
    private String videoName;
    @ApiModelProperty(name = "videoUrl", value = "教学视频在线地址", required = true)
    private String videoUrl;
    @ApiModelProperty(name = "videoIntro", value = "教学视频介绍", required = true)
    private String videoIntro;
    @ApiModelProperty(name = "showSort", value = "列表显示顺序", required = true)
    private int showSort;

    public String getVideoName() {
        return videoName;
    }

    public void setVideoName(String videoName) {
        this.videoName = videoName;
    }

    public String getVideoUrl() {
        return videoUrl;
    }

    public void setVideoUrl(String videoUrl) {
        this.videoUrl = videoUrl;
    }

    public String getVideoIntro() {
        return videoIntro;
    }

    public void setVideoIntro(String videoIntro) {
        this.videoIntro = videoIntro;
    }

    public int getShowSort() {
        return showSort;
    }

    public void setShowSort(int showSort) {
        this.showSort = showSort;
    }
}

©️2020 CSDN 皮肤主题: 黑客帝国 设计师:上身试试 返回首页