zoukankan      html  css  js  c++  java
  • Spring 集成 Swagger UI

    <!-- Spring -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-web</artifactId>
    			<version>1.5.3.RELEASE</version>
    			<exclusions>
    				<exclusion>
    					<groupId>org.springframework.boot</groupId>
    					<artifactId>spring-boot-starter-tomcat</artifactId>
    				</exclusion>
    				<exclusion>
    					<groupId>org.springframework.boot</groupId>
    					<artifactId>spring-boot-starter-logging</artifactId>
    				</exclusion>
    			</exclusions>
    		</dependency>
    
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-log4j2</artifactId>
    			<version>1.5.3.RELEASE</version>
    		</dependency>
    
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-jetty</artifactId>
    			<version>1.5.3.RELEASE</version>
    			<exclusions>
    				<exclusion>
    					<groupId>com.fasterxml.jackson.core</groupId>
    					<artifactId>jackson-annotations</artifactId>
    				</exclusion>
    			</exclusions>
    		</dependency>
    
    		<dependency>
    			<groupId>io.springfox</groupId>
    			<artifactId>springfox-swagger2</artifactId>
    			<version>2.7.0</version>
    		</dependency>
    
    		<dependency>
    			<groupId>io.springfox</groupId>
    			<artifactId>springfox-swagger-ui</artifactId>
    			<version>2.7.0</version>
    		</dependency>
    
    		<dependency>
    			<groupId>io.swagger</groupId>
    			<artifactId>swagger-annotations</artifactId>
    			<version>1.5.13</version>
    		</dependency>
    
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class ExampleController {
    
    	@RequestMapping(value = "hello/{name}", method = RequestMethod.GET)
    	public String greeting(@PathVariable("name") String name) {
    		return "hello my friend : " + name;
    	}
    	
    }
    

      

     

    访问地址 xxxx:8080/v2/api-docs 可以查看json数据

     访问 xxxx:8080/swagger-ui.html  直接查看ui

    参考文档

    http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

    http://www.conglin-site.com/document/html/1494763157.html

    https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X#apiparam

  • 相关阅读:
    CentOS实验六:配置EPEL软件源
    Linux 目录结构【转】
    man page中的数字
    Linux常用命令(一) 基础
    MVP大礼包写真集
    DNN单击事件只有在"编辑"状态下才有效的解决方案
    GridView导出到Excel和开源图表工具
    免费的DNN工具条
    在应用程序级别以外使用注册为 allowDefinition='MachineToApplication' 的节是错误的解决办法
    DotNetNuke 4.9.0安装完全教程
  • 原文地址:https://www.cnblogs.com/xuchenCN/p/6924131.html
Copyright © 2011-2022 走看看