1.配置文件pom,一定要使用2.4以上的,2.4默认请求方式是json,会导致getmapping设置参数类型对对象时,swaggerui界面不能指定为其他类型,反正就是各种坑,不建议用

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
2.使spring管理swaggerui配置
package org.liping.springribbon;

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.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@EnableSwagger2
public class Swagger2 {
//swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//为当前包路径
.apis(RequestHandlerSelectors.basePackage("org.liping.springribbon"))
.paths(PathSelectors.any())
.build();
}
//构建 api文档的详细信息函数,注意这里的注解引用的是哪个
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("Spring Boot Swagger2 ui")
//创建人
.contact(new Contact("liping1", "https://home.cnblogs.com/u/keepMoveForevery/", ""))
//版本号
.version("1.0")
//描述
.description("API 描述")
.build();
} }

3.在自己的Controler加入swagger-ui注解开启测试

package org.liping.springribbon;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
@RequestMapping(value = "/",produces = "application/json;charset=UTF-8")
@Api(value="用户controller",description="用户操作",tags={"用户操作接口"})
public class HelloControler { @Autowired
HelloService helloService; @ApiOperation(value = "hi接口名字", notes = "这是一个接口的描述")
@GetMapping(value = "/hi")
public UserModel hi(String name, int id){
UserModel userModel = new UserModel();
userModel.setId(id);
userModel.setName(name);
System.out.println("他被调用了");
return userModel;
} @ApiOperation(value = "hi1接口名字")
@RequestMapping(value = "/hi1")
public UserModel hi1(UserModel userModel){
UserModel userModel1 = new UserModel();
userModel1 = userModel;
System.out.println("他被调用了1"+ userModel.getId());
return userModel1;
} }   

下面是我用来做测试测对象代码

package org.liping.springribbon;

import io.swagger.annotations.ApiModelProperty;

public class UserModel {

    @ApiModelProperty(value="id",name="id",required=true)
private int id; private String name; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} @Override
public String toString() {
return "UserModel{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}

就这么简单,其他一些属性自行百度

下面是代码结构以及执行结果

最后是代码结构

springcloud集成swaggerui做动态接口文档的更多相关文章

  1. spring boot 2.x 系列——spring-boot 集成 Swagger2 打造在线接口文档

    文章目录 一.Springfox 与 Swagger 简介 1.1 Springfox 1.2 Swagger 1.3 OpenApi.Swagger.Springfox的关系 二.spring bo ...

  2. SpringMVC集成springfox-swagger2自动生成接口文档

    本节内容: 什么是Swaggger Springfox与Swagger的关系 SpringMVC集成springfox-swagger2 一.什么是Swaggger Swagger是一个流行的API开 ...

  3. Spring Boot 集成 Swagger,生成接口文档就这么简单!

    之前的文章介绍了<推荐一款接口 API 设计神器!>,今天栈长给大家介绍下如何与优秀的 Spring Boot 框架进行集成,简直不能太简单. 你所需具备的基础 告诉你,Spring Bo ...

  4. Spring Boot从入门到精通(十一)集成Swagger框架,实现自动生成接口文档

    Swagger是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.Swagger 是一组开源项目,其中主要要项目如下: Swagger-tools:提供各种与S ...

  5. ABP给WebApi添加SwaggerUI,生成可交互接口文档

    在ABP模板项目中,通过SwaggerUI可以为我们的WebApi生成动态的可交互接口文档页面,从而可以很方便的测试调用我们的WebApi接口. 一.集成Swagger 右键项目YoYo.Web,打开 ...

  6. Springboot集成swagger2生成接口文档

    [转载请注明]: 原文出处:https://www.cnblogs.com/jstarseven/p/11509884.html    作者:jstarseven    码字挺辛苦的.....   一 ...

  7. Java | Spring Boot Swagger2 集成REST ful API 生成接口文档

      Spring Boot Swagger2 集成REST ful API 生成接口文档 原文 简介 由于Spring Boot 的特性,用来开发 REST ful 变得非常容易,并且结合 Swagg ...

  8. 如何使用Swagger-UI在线生成漂亮的接口文档

    一.简单介绍 Swagger是一个实现了OpenAPI(OpenAPI Specification)规范的工具集.OpenAPI是Linux基金会的一个项目,试图通过定义一种用来描述API格式或API ...

  9. Spring Boot 集成 Swagger 构建接口文档

    在应用开发过程中经常需要对其他应用或者客户端提供 RESTful API 接口,尤其是在版本快速迭代的开发过程中,修改接口的同时还需要同步修改对应的接口文档,这使我们总是做着重复的工作,并且如果忘记修 ...

随机推荐

  1. 简述FPGA时序约束理论

    FPGA时序约束简介. 时序约束的场景: 在简单电路中,当频率较低时,数字信号的边沿时间可以忽略时,无需考虑时序约束.但在复杂电路中,为了减少系统中各部分延时,使系统协同工作,提高运行频率,需要进行时 ...

  2. Java 数组的三种创建方法,数组拷贝方法

    public static void main(String[] args) {//创建数组的第一种方法int[] arr=new int[6];int intValue=arr[5];//Syste ...

  3. Oracle 利用执行计划来避免排序操作

    在oracle中,利用index来避免排序 SQL) NOT NULL); SQL> CREATE INDEX IND_T_NOSORT_NAME ON T_NOSORT(NAME); SQL& ...

  4. C Primer Plus学习笔记(十三)- 结构和其他数据形式

    建立结构声明 结构声明(structure declaration)描述了一个结构的组织布局 struct book { char title[MAXTITL]; char author[MAXAUT ...

  5. Jquery改变td内容为1的颜色

    Jquery改变td内容为1的颜色<table id="tb" > <tr> <td val="1">1</td> ...

  6. 只能在执行Render() 的过程中调用 RegisterForEventValidation;

    October 17, 2008  3:28 PMMarch 29, 2013  8:28 PM Aillo 编程   0 Comments 在实现"将GridView中的数据导出到Exce ...

  7. leetcode821

    vector<int> shortestToChar(string S, char C) { vector<int> V; ; int AYC[N]; ; ; i < S ...

  8. Swagger SpringBoot 集成

    说明:Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集 ...

  9. 11-EasyNetQ之多态发布和订阅

    你能够订阅一个接口,然后发布基于这个接口的实现. 让我们看下一个示例.我有一个接口IAnimal和两个实现Cat和Dog: public interface IAnimal { string Name ...

  10. Spring Data系列之Jpa(一)

    1.Spring Data的由来 Spring Data是SpringSource基金会创下的一个简化数据库访问.支持云服务的开源框架.其主要目的是让数据库访问变的方便快捷,可以用Spring Dat ...