swagger请求参数在header中添加token

网友大部分说的是如下配置

参照配置然而没有作用

注掉改红框内的配置,在方法上加如下注释就可以用

 @ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true) })

效果如图

入参效果想有下图示例

在入参实体类配置一下即可

@Data
@ApiModel(value = "signIn",description = "账户")
public class SignIn {

    @ApiModelProperty(name = "id",dataType = "String",example = "1")
    private String id;
    @ApiModelProperty(name = "userName",dataType = "String",example = "San")
    private String userName;
    @ApiModelProperty(name = "userName",dataType = "String",example = "123456")
    private String password;


}

不是实体类的入参,还是使用

@ApiImplicitParams({ @ApiImplicitParam-------嵌套在方法上
@ApiImplicitParams({
        @ApiImplicitParam(paramType="header",name="username",dataType="String",required=true,value="用户的姓名",defaultValue="zhaojigang"),
        @ApiImplicitParam(paramType="query",name="password",dataType="String",required=true,value="用户的密码",defaultValue="wangna")
    })

 当然在postman使用时不用加此注解

原文地址:https://www.cnblogs.com/h-c-g/p/11004105.html