因为开发项目的接口需要给app,小程序测试,所以用swagger.

  1.pom.xml:

  

<dependency><!--添加Swagger依赖 -->
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.</version>
</dependency>
<dependency><!--添加Swagger-UI依赖 -->
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.</version>
</dependency>

2.写一个java的配置文件:

  

package com.atguigu.springboot.config;

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 { /**
* 添加摘要信息(Docket)
*/
@Bean
public Docket controllerApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("书法管理系统_接口文档")
.description("书法用于管理集团旗下公司的人员信息,具体包括")
.contact(new Contact("小猪不笨", null, null))
.version("版本号:1.0")
.build())
.select()
.apis(RequestHandlerSelectors.basePackage("com.atguigu.springboot.controller"))
.paths(PathSelectors.any())
.build();
} }

  3.在Controller打上swagger常用的注解:

@Api(value="部门管理基础api文档")
@RestController
@RequestMapping(value="/dept")
public class DeptController { @Autowired
DeptMapper deptMapper; /*
@ApiOperation(value="查询单个部门")
@GetMapping("/getById")
public DeptEntity getById(){
Integer id = 1;
return deptMapper.getById(id);
}*/ /*
@ResponseBody
@RequestMapping(value ="/getUserName", method= RequestMethod.GET)
@ApiOperation(value="根据用户编号获取用户姓名", notes="test: 仅1和2有正确返回")
@ApiImplicitParam(paramType="query", name = "userNumber", value = "用户编号", required = true, dataType = "Integer")
public String getUserName(@RequestParam Integer userNumber){
if(userNumber == 1){
return "张三丰";
}
else if(userNumber == 2){
return "慕容复";
}
else{
return "未知";
}
} @ResponseBody
@RequestMapping("/updatePassword")
@ApiOperation(value="修改用户密码", notes="根据用户id修改密码")
@ApiImplicitParams({
@ApiImplicitParam(paramType="query", name = "userId", value = "用户ID", required = true, dataType = "Integer"),
@ApiImplicitParam(paramType="query", name = "password", value = "旧密码", required = true, dataType = "String"),
@ApiImplicitParam(paramType="query", name = "newPassword", value = "新密码", required = true, dataType = "String")
})
public String updatePassword(@RequestParam(value="userId") Integer userId, @RequestParam(value="password") String password,
@RequestParam(value="newPassword") String newPassword){
if(userId <= 0 || userId > 2){
return "未知的用户";
} return "密码修改成功!";
}*/
}

  简单方便.

(办公)SpringBoot和swagger2的整合.的更多相关文章

  1. springBoot与Swagger2的整合

    1.在项目pom文件中引入swagger2的jar包 <!-- swagger2开始 --> <dependency> <groupId>io.springfox& ...

  2. springboot+jpa+mysql+swagger整合

    Springboot+jpa+MySQL+swagger整合 创建一个springboot web项目 <dependencies> <dependency>      < ...

  3. SpringBoot使用Swagger2实现Restful API

    很多时候,我们需要创建一个接口项目用来数据调转,其中不包含任何业务逻辑,比如我们公司.这时我们就需要实现一个具有Restful API的接口项目. 本文介绍springboot使用swagger2实现 ...

  4. SpringBoot之Swagger2文档生成

    SpringBoot之Swagger2文档生成 1.Swagger2介绍 编写和维护接口文档是每个程序员的职责,前面我们已经写好的接口现在需要提供一份文档,这样才能方便调用者使用.考虑到编写接口文档是 ...

  5. [转] spring-boot集成swagger2

    经测,spring-boot版本使用1.5.2+时需使用springfox-swagger2版本2.5+(spring-boot 1.2 + springfox-swagger2 2.2 在未扫描ja ...

  6. (九) SpringBoot起飞之路-整合/集成Swagger 2 And 3

    兴趣的朋友可以去了解一下其他几篇,你的赞就是对我最大的支持,感谢大家! (一) SpringBoot起飞之路-HelloWorld (二) SpringBoot起飞之路-入门原理分析 (三) Spri ...

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

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

  8. SpringBoot之Swagger2

    SpringBoot利用Swagger2只需配置少量的注解信息便能方便地构建强大的API文档. 1.添加maven依赖 2.创建Swagger2配置类 3.在API添加文档内容 4.访问http:// ...

  9. 【转载】SpringBoot系列——Swagger2

    微服务学习二:springboot与swagger2的集成:https://www.cnblogs.com/fengli9998/p/7522973.html 注:需要在启动类加 @EnableSwa ...

随机推荐

  1. [Swift]LeetCode775. 全局倒置与局部倒置 | Global and Local Inversions

    We have some permutation Aof [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...

  2. 美国5G:初步上线玩砸,信号难寻和4G无差别

    事件背景: 自从美国最高联邦法院给美国国会立法机关送去了传票之后,至今为止还暂时没有动静.传票限期两个月,不开庭就视为自动败诉,目前离最后的期限应该还有一个月的时间,静心等待结果就好. 不过这段时间, ...

  3. js使用面向对象编写下拉菜单

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  4. C#基础语法

    究极入门之Hello world static void Main(string[] args) { //你好,世界 Console.WriteLine("HELLO WORLD" ...

  5. 『Two 树的直径求解及其运用』

    树的直径 我们先来认识一下树的直径. 树是连通无环图,树上任意两点之间的路径是唯一的.定义树上任意两点\(u, v\)的距离为\(u\)到\(v\)路径上边权的和.树的直径\(MN\)为树上最长路径, ...

  6. 从零开始学习PYTHON3讲义(三)写第一个程序

    <从零开始PYTHON3>第三讲 本页面使用了公式插件,因博客主机过滤无法显示的表示抱歉,并建议至个人主页查看原文. ​ 我见过很多初学者,提到编程都有一种恐惧感,起源是感觉编程太难了.其 ...

  7. 关于AJAX异步请求

    一个HTTP请求由4个部分组成: *HTTP请求方法或“动作” *正在请求的URL *一个可选的请求头集合,其中可能包括身份验证信息 *一个可选的请求主体 服务器返回的HTTP响应包含3部分: *一个 ...

  8. Zookeeper~Linux环境下的部署

    介绍 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提 ...

  9. Mongodb~Linux环境下的部署~服务的部署与自动化

    <mongodb在linux上的部署> 事实上redis安装程序挺好,直接帮我们生成了服务,直接可以使用systemctl去启动它,而mongodb在这方面没有那么智能,需要我们去编写自己 ...

  10. Jexus~webApi程序的部署几个小坑

    今天上午写了Jexus~Linux环境下的部署,下午去实现了一个,出现了一些问题,下面总结一下. 一 首先要对jexus进行修改/usr/jexus/jws 删除下面的这行,解决csc文件未找到问题 ...