• 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

  • 相关阅读:
    Python3-笔记-E-005-库-系统os
    Python3-笔记-E-004-库-日历calendar
    Python3-笔记-E-003-库-日期时间datatime
    Python3-笔记-E-002-库-Unix纪元时间戳time
    Python3-笔记-E-001-库-随机数random
    Python3-笔记-D-001-异常与断言
    Python3-笔记-C-007-函数-导入模块并调用
    【bzoj2199/Usaco2011 Jan】奶牛议会——2-sat
    【bzoj1578/Usaco2009 Feb】Stock Market 股票市场——完全背包
    【bzoj1741/Usaco2005 nov】Asteroids 穿越小行星群——最小割
  • 原文地址:https://www.cnblogs.com/xuchenCN/p/6924131.html
Copyright © 2020-2023  润新知