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使用时不用加此注解

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM