1.导入swagger2

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>

2.配置类

/**
* Swagger配置
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
// 自行修改为自己的包路径
.apis(RequestHandlerSelectors.basePackage("com.xx.xx.controller"))
.paths(PathSelectors.any())
.build()
.globalOperationParameters(setHeaderToken());
} private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("平台api文档")
.description("restful 风格接口")
//服务条款网址
//.termsOfServiceUrl("http://www.hdvon.cn/")
.version("1.0")
//.contact(new Contact("xxx有限公司", "url", "email"))
.build();
} private List<Parameter> setHeaderToken() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>();
tokenPar.name("token").description("token令牌").modelRef(new ModelRef("string")).parameterType("header").required(false);
pars.add(tokenPar.build());
return pars;
} }

3.在controller上贴上相应注解

@Api(value="用户登录",description="用户登录")
@RestController
@RequestMapping("/")
public class LoginController { @ApiOperation(value = "登录并获取token", notes = "登录并获取token", httpMethod = "POST")
@PostMapping(value = "login")
public HttpResponse login(String username, String password, boolean force) {}

4.如果你的项目是springboot项目,访问http://localhost:[端口]/swagger-ui.html,就可以看到swagger的ui页面了

swagger2配置和使用的更多相关文章

  1. Swagger2配置

    配置类 package top.yalong; import org.springframework.beans.factory.annotation.Value; import org.spring ...

  2. Swagger2配置与使用

    Swagger2配置与使用 Swagger2介绍 前后端分离开发模式中,api文档是最好的沟通方式. Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 We ...

  3. springboot新增swagger2配置

    转自http://www.cnblogs.com/jtlgb/p/8532433.html SpringBoot整合Swagger2 相信各位在公司写API文档数量应该不少,当然如果你还处在自己一个人 ...

  4. 使用swagger2配置springboot时出现的问题

    这个问题踩了几次坑了,这次又遇到了,不记录一下看来是不长记性了: 测试普通的增删改查的时候,发现删除和查询是对的,可是增加和更新却数据绑定不到controller的参数上面去. 因为是自定义的实体类, ...

  5. Swagger2 配置

    1. 每个请求都需要换取key: @Bean public Docket createRestApi() { //添加head参数start ParameterBuilder appId = new ...

  6. swagger2配置详解

    1.写在controller上的注解 1.1 @Api 代码 @Api(tags = "用户相关接口", description = "提供用户相关的 Rest API& ...

  7. spring clould -多模块 -swagger2 配置 nginx 的正确设置

    #user nobody; worker_processes 2; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...

  8. SpringBoot集成Swagger2并配置多个包路径扫描

    1. 简介   随着现在主流的前后端分离模式开发越来越成熟,接口文档的编写和规范是一件非常重要的事.简单的项目来说,对应的controller在一个包路径下,因此在Swagger配置参数时只需要配置一 ...

  9. Spring Boot中使用Swagger2构建强大的RESTful API文档

    由于Spring Boot能够快速开发.便捷部署等特性,相信有很大一部分Spring Boot的用户会用来构建RESTful API.而我们构建RESTful API的目的通常都是由于多终端的原因,这 ...

随机推荐

  1. ocp题库更新,052最新考试题及答案整理-31

    31.Which two events always request the LGWR to write? A) when LGWR is notified by a server process t ...

  2. How to mount a remote directory in Linux using sshfs

    Q. I have access rights to one of the remote server through SSH protocol and there is no File share ...

  3. Ionic2使用百度地图API(JS)出现白屏解决方案

    最近自学ionic2,写了一个内嵌百度地图JS的demo,实际跑起来之后出现了大家常见的白屏问题.. 最初的实现是这样的: 首先主页内嵌了一个百度地图插件 <div id="Bmap& ...

  4. 一个网站同一域名不同目录下的文件访问到的cookie值不同是什么原因?

    一个网站(e:\test):里面包含多个目录如: html css js php img ..... 等等.然后,我在js目录里面的js文件中设置了cookie:同样也在php目录中的php文件中设置 ...

  5. 2016级算法第四次上机-E.Bamboo and the Ancient Spell

    Bamboo and the Ancient Spell 分析 可能英文读题难度比较大,但是只要看到全大写的 "THE LONGEST COMMON SUBSEQUENCE !"应 ...

  6. C#使用Redis的基本操作

    一,引入dll 1.ServiceStack.Common.dll 2.ServiceStack.Interfaces.dll 3.ServiceStack.Redis.dll 4.ServiceSt ...

  7. 4.1、支持向量机(SVM)

    1.二分类问题 在以前的博客中,我们介绍了用于处理二分类问题的Logistic Regression算法和用于处理多分类问题的Softmax Regression算法,典型的二分类问题,如图: 对于上 ...

  8. Kettle 解决数据锁的问题(事务(进程 ID 51)与另一个进程被死锁在 锁 资源上)

    1.Kettle做了一个作业, 执行的时候问题发生在步骤2和步骤3之间,也就是步骤2还未完全执行完的时候,步骤3就要更新步骤2插入的数据,造成死锁.(我的理解是既然都分开作业了,那么每个作业都是一个单 ...

  9. linux中校验文件完整性(md5,sha1)

    经常在Linux下下载软件的人,一定会有一个良好的习惯:校验文件的hash,以确定文件的完整性甚至是安全性.我配置环境的时候也恰好用到了,笔者的是一个lubuntu的机子.这里我大致做个记录.(不了解 ...

  10. python四则运算2.0

    github项目地址: https://github.com/kongkalong/python PSP 预估耗时(分钟) Planning .Estimate 48*60 Development . ...