knife4j只用此插件的最简洁开发方式
一、POM添加
在pom文件里添加包
1 <!--引入knife4j以来-->
2 <dependency>
3 <groupId>com.github.xiaoymin</groupId>
4 <artifactId>knife4j-spring-boot-starter</artifactId> <version>1.9.6</version>
5 </dependency>
二、配置添加,相当于<bean>添加
1 package com.mrliu.undertow.conf;
2
3 import com.github.xiaoymin.knife4j.spring.annotations.EnableSwaggerBootstrapUi;
4 import org.springframework.context.annotation.Bean;
5 import org.springframework.context.annotation.Configuration;
6 import springfox.documentation.builders.ApiInfoBuilder;
7 import springfox.documentation.builders.PathSelectors;
8 import springfox.documentation.builders.RequestHandlerSelectors;
9 import springfox.documentation.service.ApiInfo;
10 import springfox.documentation.service.Contact;
11 import springfox.documentation.spi.DocumentationType;
12 import springfox.documentation.spring.web.plugins.Docket;
13 import springfox.documentation.swagger2.annotations.EnableSwagger2;
14
15 /**
16 * @author liuyang
17 */
18 @Configuration
19 @EnableSwagger2
20 @EnableSwaggerBootstrapUi
21 public class Swagger2Config {
22
23 /**
24 * 创建连接的包信息
25 * <p>
26 * 配置统一返回的controller路径RequestHandlerSelectors.basePackage
27 *
28 * @return 返回创建状况
29 */
30 @Bean
31 public Docket createRestApi() {
32 return new Docket(DocumentationType.SWAGGER_2)
33 .useDefaultResponseMessages(false)
34 .apiInfo(apiInfo())
35 .select()
36 .apis(RequestHandlerSelectors.basePackage("com.mrliu.undertow.controller"))
37 .paths(PathSelectors.any())
38 .build();
39
40 }
41
42
43 /**
44 * 设置文档信息主页的内容说明
45 *
46 * @return 文档信息
47 */
48 private ApiInfo apiInfo() {
49 return new ApiInfoBuilder()
50 .title("Project textBook API ")
51 .description("服务接口")
52 .termsOfServiceUrl("http://localhost:8001/")
53 .contact(new Contact("Mr Liu", "http://localhost:8999/", "liuyang@synway.cn"))
54 .license("what")
55 .version("1.0")
56 .build();
57 }
58
59 }
apiInfo()设置后会改变如图

三、bean实体类添加
1 /**
2 * @author Administrator
3 */
4 @ApiModel("用户对象")
5 @Data
6 public class UserVO {
7
8 @ApiModelProperty(required = true, notes = "用户名", example = "blues")
9 private String name;
10
11 @ApiModelProperty(required = true, notes = "用户返回消息", example = "hello world")
12 private String words;
13
14
15 public UserVO(String name, String words) {
16 this.name = name;
17 this.words = words;
18 }
19 }
主要是添加注解
@ApiModel("用户对象") -----实体类注解添加 添加后结果如图所示: 
@ApiModelProperty(required = true, notes = "用户名", example = "blues") 字段注解添加 添加后结果如图所示: 
四、Controller添加
- 1、GET方式访问
1 package com.mrliu.undertow.controller;
2
3 import com.mrliu.undertow.base.Results;
4 import com.mrliu.undertow.pojo.UserVO;
5 import io.swagger.annotations.*;
6 import org.springframework.web.bind.annotation.GetMapping;
7 import org.springframework.web.bind.annotation.PathVariable;
8 import org.springframework.web.bind.annotation.RequestMapping;
9 import org.springframework.web.bind.annotation.RestController;
10
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
13 import java.io.IOException;
14
15 /**
16 * @author Administrator
17 */
18 @Api(tags = "HELLO CONTROLLER 测试功能接口")
19 @RestController
20 public class HelloController {
21
22
23 @ApiImplicitParams({
24 @ApiImplicitParam(name = "name",value = "用户名称",required = true,dataType = "String",paramType = "path",example = "blues")
25 })
26 @ApiResponses(value = {
27 @ApiResponse(code = 200, message = "接口返回成功状态"),
28 @ApiResponse(code = 500, message = "接口返回未知错误,请联系开发人员调试")
29 })
30 @ApiOperation(value = "Hello 测试接口", notes = "访问此接口,返回hello语句,测试接口")
31 @GetMapping("hello/{name}")
32 public Results<UserVO> hello(@PathVariable String name){
33 UserVO userVO = new UserVO(name,"hello " + name);
34 Results<UserVO> results = new Results<>(200,"SUCCESS", userVO);
35 return results;
36 }
37 }界面生成:

- 2、POST方式访问
1 @Api(tags = "HELLO CONTROLLER 测试功能接口")
2 @RestController
3 public class HelloController {
4
5
6 @ApiImplicitParams({
7 @ApiImplicitParam(name = "name",value = "用户名称",required = true,dataType = "String",paramType = "path",example = "blues")
8 })
9 @ApiResponses(value = {
10 @ApiResponse(code = 200, message = "接口返回成功状态"),
11 @ApiResponse(code = 500, message = "接口返回未知错误,请联系开发人员调试")
12 })
13 @ApiOperation(value = "Hello 测试接口", notes = "访问此接口,返回hello语句,测试接口")
14 @PostMapping("hello/{name}")
15 public Results<UserVO> hello(@RequestBody UserVO userVO){
16 Results<UserVO> results = new Results<>(200,"SUCCESS", userVO);
17 return results;
18 }
19 }
五、访问URL
http://localhost:7788/doc.html
六、兼容swagger-ui访问
http://localhost:7788/swagger-ui.html
七、测试

填入参数
对象请求访问

八、API文档复制

复制后可生成markdow文档,使用showdoc,即可翻译成文档,下载html、PDF、word等格式
源码地址:https://github.com/liushaoye/knife4j.git 欢迎点赞,分享,推荐
knife4j只用此插件的最简洁开发方式的更多相关文章
- 【eclipse插件开发实战】Eclipse插件开发4——插件JDE、PDE开发方式及plugin.xml配置文件结构
Eclipse插件开发4--插件JDE.PDE开发方式及plugin.xml配置文件结构 开发方式分为:java开发环境JDE开发插件的方式和插件开发环境PDE开发插件方式. 插件通过添加到预定义的扩 ...
- 2022IDEA配置启动lilishop的swagger展示
目录 一.概述 二.基本构建 三.Git 导入编译器 四.模块描述浅析 五.配置文档 1.注释配置文件 2.添加配置 3.暂时关闭权限 4.浏览器测试访问 5.其他需要修改模块 六.参考文献 结语 一 ...
- Xcode插件优缺点对比(推荐20款插件)
本文大致整理了自己用过的一些插件的使用感想(就是好不好用). 在那之前先简单贴两条插件须知,知道的可以忽略. 1.Alcatraz 类似于管理第三方库的cocoapods,管理插件也有个Alcatra ...
- 图片延迟加载jquery插件imgLazyLoading
实现了图片延迟加载功能,插件代码非常简洁,且每个功能都把注释写得非常详细,适合网友们学习,好好利用哦 引入图片延迟加载Jquery插件文件后,页面使用代码如下: <script type=&qu ...
- 12个强大的Chrome插件
Chrome功能强大,也得益于其拥有丰富的扩展资源库.Chrome Web Store里有各种各样的插件,可以满足你使用Chrome时的各种要求.和Firefox一样,Chrome的扩展非常容易安装, ...
- 【转】Xcode 插件优缺点对比(推荐 20 款插件)
[转自]http://www.cnblogs.com/dsxniubility/p/5099191.html 1.Alcatraz 类似于管理第三方库的cocoapods,管理插件也有个Alcatra ...
- xcode 必用插件二
本文大致整理了自己用过的一些插件的使用感想(就是好不好用). 在那之前先简单贴两条插件须知,知道的可以忽略. 1.Alcatraz 类似于管理第三方库的cocoapods,管理插件也有个Alcatra ...
- 精心挑选的12款优秀 jQuery Ajax 分页插件和教程
在这篇文章中,我为大家收集了12个基于 jQuery 框架的 Ajax 分页插件,这些插件都提供了详细的使用教程和演示.Ajax 技术的出现使得 Web 项目的用户体验有了极大的提高,如今借助优秀的 ...
- 转:精心挑选的12款优秀 jQuery Ajax 分页插件和教程
在这篇文章中,我为大家收集了12个基于 jQuery 框架的 Ajax 分页插件,这些插件都提供了详细的使用教程和演示.Ajax 技术的出现使得 Web 项目的用户体验有了极大的提高,如今借助优秀的 ...
随机推荐
- 从MVC到DDD的架构演进
DDD这几年越来越火,资料也很多,大部分的资料都偏向于理论介绍,有给出的代码与传统MVC的三层架构差异较大,再加上大量的新概念很容易让初学者望而却步.本文从MVC架构角度来讲解如何演进到DDD架构. ...
- Solution -「CF 1119F」Niyaz and Small Degrees
\(\mathcal{Description}\) Link. 给定一棵 \(n\) 个结点的树,边有边权,对于每个整数 \(x\in[0,n)\),求出最少的删边代价使得任意结点度数不超过 ...
- Python实例:贪吃蛇(简单贪吃蛇编写)🐍
d=====( ̄▽ ̄*)b 叮~ Python -- 简易贪吃蛇实现 目录: 1.基本原理 2.需要学习的库 3.代码实现 1.基本原理 基本贪吃蛇所需要的东西其实很少,只需要有一块让蛇动的屏幕, 在 ...
- OpenLDAP测试搭建
目录 ldap介绍 测试环境 安装LDAP服务端 设置LDAP的root密码 配置LDAP服务端 创建LDAP证书 设置LDAP数据库 创建LDAP用户 添加防火墙规则 开启LDAP日志 配置LDAP ...
- 宿主机ping不通虚拟机,虚拟机能ping通宿主机
最近,微信提升群里好几个小伙伴遇到了如题的问题. 问了下原因,原来是我说的把宿主机网卡ip获取方式改为自动,结果他们把宿主机上虚拟网卡的ip改为自动了. 当然,分析"宿主机ping不通虚拟机 ...
- IP欺骗实验
实验目的 1.掌握IP欺骗的原理 2.学会利用IPSpoof软件工具进行伪造源IP地址的IP欺骗. 实验内容 使用IPSpoof进行本机IP地址修改,与目标主机通信,进行IP欺骗实验 实验环境描述 1 ...
- 【C# 线程】内存模型(C#)---非常重要 【多线程、并发、异步的基础知识】
内存模型概述 MSDN:理论与实践中的 C# 内存模型 MSDN:理论与实践中的 C# 内存模型,第 2 部分 内存模型就是内存一致性模型. 以下内如来自维基百科 内存一致性模型列表 线性一致性(Li ...
- Neo4j入门日志(一)导入数据
本文主要来源于: neo4j的官方文档 使用的是neo4j官方提供的导入方式,即使用import,在cmd中进行导入. 1.导入的基本方式 bin/neo4j-admin import --datab ...
- 【C#版本】微信公众号模板消息对接(一)(图文详解)
特此说明:本篇文章为个人原创文章,创作不易,未经作者本人同意.许可等条件,不得以任何形式搬运.转载.抄袭(等包括但不限于此手段)本文章,否则保留追究有关侵权人责任的权利 一.认识微信公众号模板消息 什 ...
- 【译】在 ASP.NET 和 ASP.NET Core 之间共享代码
原文 | Ken 翻译 | 郑子铭 随着 .NET 6 的发布,使用 ASP.NET Core 可以获得更多好处.但是将现有代码迁移到 ASP.NET Core 通常听起来像是一项巨大的投资.今天我们 ...