码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Boot 整合Swagger2

时间:2021-01-25 10:42:42      阅读:0      评论:0      收藏:0      [点我收藏+]

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

Spring Boot 整合Swagger2

依赖导入

<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>
 
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>

编写配置类

@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<String,Object> 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!