zoukankan      html  css  js  c++  java
  • swagger文档

    关键配置文件

    spring boot demo pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.2.5.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
    
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

    maven编辑安装

    pom.xml --> 右键 --> run as --> maven install --> 会将项目打包jar包放在maven指定的资源目录下

    这样同maven配置的项目就可以使用这个项目的资源

    Swagger文档与接口测试

    pom.xml

    <!-- swagger -->
            <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>

    配置类

    package com.louis.mango.config;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import springfox.documentation.builders.ApiInfoBuilder;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
        
        
        @Bean
        public Docket createRestApi(){
            return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                    .apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
        }
    
        private ApiInfo apiInfo(){
            return new ApiInfoBuilder().build();
        }
    }

    http://127.0.0.1:9000/swagger-ui.html

     Eclipse设置添加注释时自动添加时间

    Java --> code style --> code templates --> comments --> types

    /**
     * @author ${user}
     * @version ${date} ${time}
     * ${tags}
     */

    常用网址

    banner字符生成

    http://www.network-science.de/ascii/

  • 相关阅读:
    jdbc数据库连接
    判断集合元素唯一的原理-ArrayList的contains和HashSet的contains、add。Map接口、 集合嵌套
    集合、Iterator迭代器、增强for循环、泛型、List接口、Set接口
    String类、字符串缓冲区、正则表达式、
    Date、DateFormat类、Calendar类、基本类型包装类、System类、Math类、Arrays类、大数据运算类
    Java的API及Object类
    java学习中自己平时不注意的一点知识点1:基础知识第一部分
    匿名对象、内部类、包的声明与访问、访问修饰符、
    java 方法重载,引用数据类型整理 ArrayList集合整理
    java 二维数组 方法知识整理
  • 原文地址:https://www.cnblogs.com/perfei/p/12496203.html
Copyright © 2011-2022 走看看