其他分享
首页 > 其他分享> > Swagger和Postman的配置和使用

Swagger和Postman的配置和使用

作者:互联网

Swagger

1. 配置

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>2.8.0</version>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>2.8.0</version>
    </dependency>
@Configuration
@EnableSwagger2
public class Swagger2Setting {
    @Bean
    public Docket createRestAPI(){
        return new Docket(DocumentationType.SWAGGER_2)
                //.apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.crab.classfight.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("classfight项目")
                .description("这里是classfight项目的API列表说明")
                .contact("crab")
                .version("1.0")
                .build();
    }
}
    @DeleteMapping(value = "/deleteUser/{username}")
    @ApiOperation("删除一个用户")
    public void deleteUser(@PathVariable("username") String username){
        userService.deleteUserByName(username);

    }
@RestController
@Api("用户相关的API")
public class UserController {
}


@ApiOperation(value = "添加一个用户")
还有相关其他的注解,这里不举例了

Postman

标签:username,Swagger,Postman,配置,ApiOperation,注解,springfox,public
来源: https://www.cnblogs.com/pycrab/p/10567749.html