Spring Boot 整合Swagger2

2021-03-06 02:29

阅读:471

标签:ali   url   return   ase   XML   inf   sele   导入   算法   

Spring Boot 整合Swagger2

依赖导入

io.springfox
        springfox-swagger2
        2.9.2io.springfox
        springfox-swagger-ui
        2.9.2

编写配置类

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.xy.video.controller"))
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("毕设测试Swagger")
                .contact(new Contact("念月",
                        "https://www.cnblogs.com/zero-vic/",
                        "1623272666@qq.com"))
                .description("喜欢就去给她说吧,不要给自己留遗憾了!")
                .version("5.2.0")
                .termsOfServiceUrl("http://baidu.com")
                .license("LICENSE")
                .licenseUrl("链接地址")
                .build();
    }

}

Controller层

@RestController
@Api(tags = "用于用户管理的接口")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("user")
    @ApiOperation(value = "用户查询所有接口",notes = "分页查询用户信息")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功"),
            @ApiResponse(code = 500, message = "操作失败,根据msg查看具体的错误信息")
    })
    public Map findAllUser(){
        return userService.findAllUser();
    }
}

pojo

@ApiModel
public class User implements Serializable {
    /**
     * id(雪花算法生成)
     */
    @ApiModelProperty(value = "用户ID",name = "id",dataType = "long",required = true)
    private Long id;

地址:http://localhost:8080/swagger-ui.html

Spring Boot 整合Swagger2

标签:ali   url   return   ase   XML   inf   sele   导入   算法   

原文地址:https://www.cnblogs.com/zero-vic/p/14313187.html


评论


亲,登录后才可以留言!