The Best APIs are Built with Swagger Tools

 
 
1.导入依赖
<!-- swagger -->
<dependency> <groupId> io.springfox </groupId> <artifactId> springfox-swagger2 </artifactId> <version> 2.5.0 </version> </dependency> <dependency> <groupId> io.springfox </groupId> <artifactId> springfox-swagger-ui </artifactId> <version> 2.5.0 </version> </dependency>
2.配置
EnableSwagger2
@SpringBootApplication
@EnableSwagger2
    public class DemoApplication implements ApplicationRunner {

    public static void main(String[] args) {
 
 

3.配置Swagger

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()  // 选择那些路径和api会生成document
            .apis(RequestHandlerSelectors.any()) // 对所有api进行监控
            .paths(PathSelectors.any()) // 对所有路径进行监控
            .build();
}


private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
            .title("Spring Boot中使用Swagger2构建RESTful APIs")
            .description("更多Spring Boot相关文章请关注:http://blog.didispace.com/")
            .termsOfServiceUrl("http://blog.didispace.com/")
            .contact("程序猿DD")
            .version("1.0.5555")
            .build();
}

4.添加api说明

@ApiOperation(value="根据map查询",notes = "这是个测试controller没有参数")
@ApiImplicitParam(name="无",value="无",required = false,dataType = "heh")
@RequestMapping("/queryMap")
public Object queryByMap() {
    System.out.println("============================================================================");
    HashMap<String, Object> maps = new HashMap<>();

5.访问localhost:8080/swagger-ui.html

猜你喜欢

转载自blog.csdn.net/qq_27986007/article/details/81065555