swagger通用响应结果字段显示不全或返回数据类型不显示

目录

swagger版本

springboot版本

通用响应实体类

工具类

错误显示效果

正确显示效果

解决办法


swagger版本

使用knife4j- 4.5.0结合最新openapi3规范

        <!-- knife4j   使用openapi3规范  https://openapi.apifox.cn/   -->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
            <version>4.5.0</version>
        </dependency>

springboot版本

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.11</version>
    </parent>

通用响应实体类

@Data
@Schema
public class Dto<T> {

    @Schema(description = "状态码")
    private Integer code=200;

    @Schema(description="返回信息")
    private String message;

    @Schema(description="返回数据")
    private T data;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @Schema(description="当前时间")
    private Date currentDate=new Date();

}

工具类

public class DtoUtil implements Serializable {


    /**
     *
     * @param
     * @return
     */
    public static Dto returnSuccess(){
        Dto dto=new Dto();
        dto.setMessage("success");
        return dto;
    }

    /**
     *
     * @param data 返回的数据对象 object类型
     * @return
     */
    public static Dto returnDataSuccess(Object data){
        Dto dto=new Dto();
        dto.setData(data);
        return dto;
    }

    public static Dto returnMsgSuccess(String msg){
        Dto dto=new Dto();
        dto.setData(msg);
        return dto;
    }

    /**
     *
     * @param message
     * @return
     */
    public static Dto returnFail(String message){
        Dto dto=new Dto();
        dto.setMessage(message);
        dto.setCode(500);
        return dto;
    }

    /**
     * @param message
     * @param
     * @return
     */
    public static Dto returnFailWithData(String message,Object data){
        Dto dto=new Dto();
        dto.setCode(500);
        dto.setMessage(message);
        dto.setData(data);
        return dto;
    }
}

错误显示效果

正确显示效果

解决办法

去除通用响应实体类上@Schema注解中相应参数或者删除实体类上该注解即可

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

W先生'

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值