knife4j集合化postman

knife4j集合化postman

01 knife4j的介绍

  • 基于 JavaMVC的集成框架swagger的进一步强化,在原有通过注释就能生成文档的前身swagger-bootstrap-ui之上,增加了postman的测试功能,优化了文档的UI界面,在测试api接口的方面有了极大的进步

02 前期准备

1.引入依赖

<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <version>2.0.9</version>
</dependency>

2.配置yml文件

server:
  port: 8080
  servlet:
    context-path: /web

# 配置数据源
spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

3.引入配置类

@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))//扫描的包路径
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档的标题")//文档标题
                .version("1.0.0")//文档版本说明
                .description("文档的描述")//文档的描述
                .build();
    }

}

03 测试

1.测试的实体类

@ApiModel("类别实体类")//用于标记实体类
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Category {
    @ApiModelProperty("类别编码")//用于标记实体类属性作用
    private Long categoryId;
    private String categoryName;
    private String categoryPicture1;
    private String categoryPicture2;
}

2.测试的控制类

@Api(tags = "类别模块")//用于标记整个控制模块
@RestController
@RequestMapping("/category")
public class CategoryController {
	//用于标记该路径,value是标记该路径名,notes是详细的解释
    @ApiOperation(value = "查询类别",notes = "根据类别id查询类别" )
    @GetMapping("/select")
    public Category select(Long categoryId){
        Category category = new Category();

        return category;

    }
    @ApiImplicitParam(name = "categoryId",value = "类别编号",required = true)//用于标记返回值,同样的,name是标记名字,value是解释
    @PostMapping("/post")
    public Category post(Long categoryId){
        Category category = new Category();
        return category;
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId",value = "类别编号",required = true),
            @ApiImplicitParam(name = "categoryName",value = "类别名字",required = true),
            @ApiImplicitParam(name = "categoryPicture1",value = "类别图片",required = false),
    })//批量标记返回值
    @PostMapping("/set")
    public Category set(Long categoryId,String categoryName,String categoryPicture1){
        Category category = new Category();
        return category;
    }
    @GetMapping("/delete")
    public Category delete(){
        Category category = new Category();
        return category;

    }
}

3.访问生成的文档

  • 项目启动后访问localhost:端口号/根路径/doc.html

在这里插入图片描述

4.API接口测试

  • 在类别模块中选择需要测试的接口

在这里插入图片描述

5.调试选项

  • 在调试选项中就可以像postman一样使用了

在这里插入图片描述

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

宣布无人罪

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

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

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

打赏作者

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

抵扣说明:

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

余额充值