日常开发中,总有些接口必须带上token才可以访问。

swagger请求参数在header中添加token

我通常的写法:

@ApiOperation("个人信息查询") @GetMapping("detail") @ApiImplicitParams( {@ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true)} ) public JsonData detail() { UserVO userVO = userService.findUserDetail(); return JsonData.buildSuccess(userVO); }

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

@ApiImplicitParams({ @ApiImplicitParam-------嵌套在方法上

swagger表现:

springboot怎么带header请求(spring-boot接口header带必传参数token写法)(1)

{ "code": 0, "data": { "id": 1, "name": "zhangsan", "slogan": "Talk is cheap, show me the code", "sex": 1, "points": 0, "mail": "295789798@qq.com", "head_img": "http://www.baidu.com" }, "msg": null }

过年了,有假期,好好充电,明年金三银四额!

,