首先,在pom.xml中添加依赖

<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.</version>
</dependency>

然后在启动类中添加Swagger2 java配置文件

package com.example.demomybatis;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
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; @SpringBootApplication
@EnableSwagger2
@MapperScan("com.example.demomybatis.mapper")
public class DemoMybatisApplication { public static void main(String[] args) {
SpringApplication.run(DemoMybatisApplication.class, args);
} @Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demomybatis.Controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
} private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("测试接口平台API")
.description("cathy demo API.")
.termsOfServiceUrl("Terms of service")
.contact(new Contact("ylw","",""))
.version("1.0")
.build();
}
}

在上面这个代码中,为swagger加入的部分是

最后,访问http://localhost:8080/swagger-ui.html

springboot整合swagger笔记的更多相关文章

  1. SpringBoot 整合swagger

    springBoot 整合swagger 1.pom.xml 配置 <dependency> <groupId>io.springfox</groupId> < ...

  2. SpringBoot整合Swagger和Actuator

    前言 本篇文章主要介绍的是SpringBoot整合Swagger(API文档生成框架)和SpringBoot整合Actuator(项目监控)使用教程. SpringBoot整合Swagger 说明:如 ...

  3. 【SpringBoot | Swagger】SpringBoot整合Swagger

    SpringBoot整合Swagger 1. 什么是Swagger Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.简单说就是项目跑起来了, ...

  4. springboot整合swagger。完爆前后端调试

    web接口开发时在调试阶段最麻烦的就是参数调试,前端需要咨询后端.后端有时候自己也不是很了解.这时候就会造成调试一次接口就需要看一次代码.Swagger帮我们解决对接的麻烦 springboot接入s ...

  5. SpringBoot整合Swagger实战

    源码地址:https://github.com/laolunsi/spring-boot-examples 目前SpringBoot常被用于开发Java Web应用,特别是前后端分离项目.为方便前后端 ...

  6. SpringBoot整合Swagger测试api构建

    @Author:SimpleWu 什么是Swagger? Swagger是什么:THE WORLD'S MOST POPULAR API TOOLING 根据官网的介绍: Swagger Inspec ...

  7. SpringBoot整合swagger

    Swagger使用 Swagger有什么用? swagger是一个流行的API开发框架,这个框架以“开放API声明”(OpenAPI Specification,OAS)为基础, 对整个API的开发周 ...

  8. springboot入门系列(二):SpringBoot整合Swagger

    上一篇<简单搭建SpringBoot项目>讲了简单的搭建SpringBoot 项目,而 SpringBoot 和 Swagger-ui 搭配在持续交付的前后端开发中意义重大,Swagger ...

  9. SpringBoot整合Swagger初探

    当下的Web项目大都采用前后端分离+分布式微服务的架构.前后端分离式的开发中,前端开发人员要与后端开发人员协商通信接口,约定接口规范.因此对于开发人员来说能够维持一份及时更新且完整全面的API文档会大 ...

随机推荐

  1. GUI应用程序架构的十年变迁:MVC,MVP,MVVM,Unidirectional,Clean

    十年前,Martin Fowler撰写了 GUI Architectures 一文,至今被奉为经典.本文所谈的所谓架构二字,核心即是对于对于富客户端的 代码组织/职责划分 .纵览这十年内的架构模式变迁 ...

  2. php自建静态博客步骤

    进入博客目录新建index.php页面 <?php require “XXXX/index.html”;//引入html页面 是否能进入localhost/xxx/index.php 注意,ph ...

  3. 提取url中参数的方法(转换成json格式)

    还是直接上代码吧. //将url中的参数获取到并抓换成json格式 function serilizeUrl(url){ var urlObject={}; //1.正则匹配是不是以?结尾 if(/\ ...

  4. 关于easyui 窗口位置的调整

    (一)easyui 默认的窗口位置 浏览器中间 (二)可直接在style里进行更改 <div id="news_dialog" class="easyui-wind ...

  5. Stage6--Python简单爬虫

    正则表达式简单介绍 正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串.将匹配的子串做替换或者从某个串中取出符合某个条件的子串等. 字符 ...

  6. Android中的Service与进程间通信(IPC)详解

    Service 什么是Service 在后台长期运行的没有界面的组件.其他组件可以启动Service让他在后台运行,或者绑定Service与它进行交互,甚至实现进程间通信(IPC).例如,可以让服务在 ...

  7. sqlServer拼结列字符串

    with table1(sessionID,message,createTime)as(select 1 ,'hello' ,'2014/5/6' union allselect 1 ,'word' ...

  8. Android 自定义View实现SegmentControlView(自定义多样式tablayout)

    偷懒一下,不做过多阐述 参考资源: Android 自定义View实现SegmentControlView : https://blog.csdn.net/a512337862/article/det ...

  9. KVM虚拟化学习记录

    请查看我的有道云笔记: http://note.youdao.com/noteshare?id=ed7308eeb1ee675b406494f4ba042ba4&sub=047FD8C61BA ...

  10. git 解决冲突方法

    转载:http://www.cnlvzi.com/index.php/Index/article/id/119 当共享一个项目后提交冲突时 git push -f 强制推送本地的替换服务端 git f ...