其中ResponseStatus封装
package tech.pdai.springboot.knife4j.constant;import lombok.AllArgsConstructor;import lombok.Getter;import java.util.Arrays;import java.util.Collections;import java.util.List;/** * @author pdai */@Getter@AllArgsConstructorpublic enum ResponseStatus {SUCCESS("200", "success"),FAIL("500", "failed"),HTTP_STATUS_200("200", "ok"),HTTP_STATUS_400("400", "request error"),HTTP_STATUS_401("401", "no authentication"),HTTP_STATUS_403("403", "no authorities"),HTTP_STATUS_500("500", "server error");public static final List<ResponseStatus> HTTP_STATUS_ALL = Collections.unmodifiableList(Arrays.asList(HTTP_STATUS_200, HTTP_STATUS_400, HTTP_STATUS_401, HTTP_STATUS_403, HTTP_STATUS_500));/*** response code*/private final String responseCode;/*** description.*/private final String description;}Controller接口package tech.pdai.springboot.knife4j.controller;import io.swagger.annotations.Api;import io.swagger.annotations.ApiImplicitParam;import io.swagger.annotations.ApiImplicitParams;import io.swagger.annotations.ApiOperation;import org.springframework.http.ResponseEntity;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import tech.pdai.springboot.knife4j.entity.param.AddressParam;/** * Address controller test demo. * * @author pdai */@Api(value = https://www.isolves.com/it/cxkf/kj/2022-07-14/"Address Interfaces", tags = "Address Interfaces")@RestController@RequestMapping("/address")public class AddressController {/*** http://localhost:8080/address/add .** @param addressParam param* @return address*/@ApiOperation("Add Address")@PostMapping("add")@ApiImplicitParams({@ApiImplicitParam(name = "city", type = "query", dataTypeClass = String.class, required = true),@ApiImplicitParam(name = "zipcode", type = "query", dataTypeClass = String.class, required = true)})public ResponseEntity运行测试自定义用户主页

文章插图
model模型

文章插图
全局参数 和配置

文章插图
自定义文档

文章插图
接口文档和测试接口

文章插图
示例源码其它旧版本的实现:
- swagger2
- Swagger2+BootstrapUI
- Knife4j v2
https://github.com/realpdai/tech-pdai-spring-demos
更多内容告别碎片化学习,无套路一站式体系化学习后端开发: Java 全栈知识体系(https://pdai.tech)
【SpringBoot接口 - 如何生成接口文档之Swagger技术栈?】
推荐阅读
- .Net WebApi 实现 接口版本控制并打通Swagger支持
- bmi|如何判断自己是否超重?看这4组数据就足够!
- |钓鱼用具商标应该怎么挑选?这几招教你如何选择好商标!
- 王者荣耀空白id代码如何复制?
- type-c接口是什么意思?
- 如何解决恐惧心理 无助感
- 如何一键恢复桌面图标?
- |夏季高温如何钓混养塘?全程打浮,教你盘哭黑坑老板!
- 婆媳最好的相处方式 婆媳关系如何相处
- 如何做肉松给宝宝吃
