使用基于swagger的knife4j自动生成接口文档

编程入门 行业动态 更新时间:2024-10-25 14:25:23

使用基于swagger的knife4j<a href=https://www.elefans.com/category/jswz/34/1766270.html style=自动生成接口文档"/>

使用基于swagger的knife4j自动生成接口文档

添加swagger依赖springfox,添加knife4j依赖

<dependency><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId>
</dependency>
<dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>3.0.2</version>
</dependency>
<dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-openapi3-spring-boot-starter</artifactId><version>4.0.0</version>
</dependency>

接口代码,文档空格使用全角格式的空格

import javax.validation.Valid;
import java.util.List;
import java.util.Set;import com.googlemon.collect.Sets;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;@Tag(name = "xx接口", description = "xxxxxController")
@RestController
@RequestMapping("/xx")
public class xxxxxController {@ApiOperation(tags = "xx接口", value = "xx",notes = "功能:xxxxx。  \n" +"业务逻辑:  \n" +" xxxxx”。  \n" +"备注:  \n" +" xxxxxx")@PostMapping(value = "/xxx/xx")public ResponseEntity<XXResponse> xxx(@RequestBody @Valid XXRequest xxRequest) {return ResponseEntity.status(HttpStatus.CREATED).body(xxService.xxx(xxRequest));}
}

使用knief访问
在接口代码中有接口描述,可以借助基于swagger的knife4j自动生成接口文档说明。

http://localhost:8080/xxx/doc.html#/home

支持MarkDown、html、word、openApi 4种格式的接口文档

也支持原有的swagger访问

http://localhost:8080/xxxx/swagger-ui/#/

更多推荐

使用基于swagger的knife4j自动生成接口文档

本文发布于:2023-11-15 22:40:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自动生成   接口   文档   swagger   knife4j

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!