您当前的位置: 首页 >  spring

梁云亮

暂无认证

  • 1浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SpringBoot 整合 knife4j

梁云亮 发布时间:2021-11-30 08:43:38 ,浏览量:1

第一步:添加Maven依赖

    com.github.xiaoymin
    knife4j-spring-boot-starter
    3.0.3

第二步:修改application.yml文件
#配置swagger配置
knife4j:
#    basic:
#        username: admin
#        password: 666666
#        enable: true #开启认证
    production: false #默认是false ,屏蔽所有Swagger的相关资源
    enable: true #是否开启swagger
第三步:测试代码 Dept.java
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel(value = "Dept",description = "部门信息")
public class Dept implements Serializable {
    private static final long serialVersionUID = -4383838089518165322L;

    /**
     * 部门编号
     */
    @ApiModelProperty("部门编号")
    private Integer deptno;

    /**
     * 部门名称
     */
    @ApiModelProperty("部门名称")
    private String dname;

    /**
     * 部门地址
     */
    @ApiModelProperty("部门地址")
    private String loc;
}
DeptController.java
@Api(tags = "用户信息管理", value = "用户接口")
@RestController
@RequestMapping("/user")
public class DeptController {
    @ApiResponse(message = "测试", code = 200)
    @ApiOperation(value = "fun", notes = "测试方法fun", httpMethod = "GET")
    @GetMapping("/fun")
    public String fun() {
        return "fun";
    }

    @PutMapping(value = "/v1/{dname}")
    @ApiOperation(value = "修改部门信息", notes = "", httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "query", name = "deptno", value = "部门ID", required = true, dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(paramType = "path", name = "dname", value = "部门名称", required = true, dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = "dept", value = "用户实体", required = true, dataType = "Dept", dataTypeClass = Dept.class)
    })
    public String fun(@RequestParam(name = "deptno", value = "deptno", required = false) Integer deptno,
                      @PathVariable(value = "dname", required = true) String dname,
                      @RequestBody(required = true) Dept dept,
                      HttpServletRequest request) {
        String token = request.getHeader("token");
        return token + " " + deptno + " " + dname + " " + dept;
    }
}
测试

网址:http://localhost:8080/doc.html 效果: 在这里插入图片描述

关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0413s