当前位置:网站首页>knife4j 初次使用
knife4j 初次使用
2022-06-12 07:14:00 【Aimyone】
1,前言
最近换了一个项目,发现项目不用swagger,而是使用knife4j,使用下来的感受就是,不得不说,还是knife4j用起来比较顺手。
毕竟Knife4j是swagger的升级版,在调试,界面排版等方面都不错。
2,配置knife4j
2.1 引入依赖
<!--swagger接口文档-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.8</version>
</dependency>
<!-- knife4j -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-aggregation-spring-boot-starter</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-ui</artifactId>
<version>2.0.8</version>
</dependency>
2.2 配置文件
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
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.EnableSwagger2WebMvc;
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {
@Bean
public Docket defaultApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("XXX管理系统后台接口文档")
.apiInfo(defaultApiInfo())
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo defaultApiInfo() {
return new ApiInfoBuilder()
.title("管理系统后台接口文档")
.description("管理系统后台接口文档")
.contact(new Contact("开发组", "", ""))
.version("1.0")
.build();
}
}
2.3 访问
通过访问路径:http://localhost:8080/doc.html
判断配置是否成功,成功的话就会有页面出来
2.4 代码接口描述注解使用
Controller
@Api 接口分类描述
@ApiOperation 接口方法描述
@Api(tags = "用户")
@RestController
@RequestMapping("/user")
public class UserController {
@ApiOperation("添加")
@PostMapping("/add")
public UserVO add(@RequestBody @Valid UserAddRequest userAddRequest) {
// 将数据写到数据库
**加粗样式** return null;
}
@ApiOperation("修改")
@PostMapping("/edit")
public UserVO edit(@RequestBody @Valid UserEditRequest userEditRequest) {
// 修改数据库的数据
return null;
}
@ApiOperation("查找")
@GetMapping("/find")
public List<UserVO> find(UserQueryRequest userQueryRequest) {
return null;
}
@ApiOperation("删除")
@PostMapping("/delete")
public void delete(Long id) {
// 将数据库数据删除
}
}

Entity
@ApiModel
@ApiModelProperty
@NotNull
@NotBlank
@Data
@ApiModel("修改用户", description = "用户描述")
public class UserEditRequest {
@ApiModelProperty(value = "用户ID", required = true)
@NotNull(message = "用户ID不能为空")
private Long id;
@ApiModelProperty(value = "用户名", required = true)
@NotBlank(message = "用户名不能为空")
private String userName;
@ApiModelProperty("昵称")
private String nickName;
@ApiModelProperty("邮箱")
private String email;
}

很不错的博客:
官网:
https://doc.xiaominfo.com/knife4j/documentation/description.html
边栏推荐
- Kotlin插件 kotlin-android-extensions
- 【图像检测】基于深度差分和PCANet实现SAR图像变化检测附matlab代码
- Dynamic coordinate transformation in ROS (dynamic parameter adjustment + dynamic coordinate transformation)
- Stm32cubemx learning (I) USB HID bidirectional communication
- d中的解耦
- libprint2
- Matlab 6-DOF manipulator forward and inverse motion
- sql server 2019安装出现错误,如何解决
- d不能用非常ctfe指针
- Embedded gd32 code read protection
猜你喜欢

Study on display principle of seven segment digital tube

2022电工(初级)考试题库及模拟考试
![[image denoising] image denoising based on nonlocal Euclidean median (nlem) with matlab code](/img/1e/386cf601f8f60197adbc853f321472.png)
[image denoising] image denoising based on nonlocal Euclidean median (nlem) with matlab code

8086/8088 instruction execution pipeline disconnection reason

Putty installation and use

5 ROS simulation modeling (4-navigation navigation simulation)

A journey of database full SQL analysis and audit system performance optimization

RT thread studio learning (VII) using multiple serial ports

leetcode. 39 --- combined sum

Scons编译IMGUI
随机推荐
Freshmen are worried about whether to get a low salary of more than 10000 yuan from Huawei or a high salary of more than 20000 yuan from the Internet
LVDS drive adapter
TypeScript基础知识全集
Introduction to JDE object management platform and use of from
公众号也能带货?
Problems encountered in learning go
RT thread studio learning (x) mpu9250
RT thread studio learning (VII) using multiple serial ports
1. Foundation of MySQL database (1- installation and basic operation)
Troubleshooting of cl210openstack operation -- Chapter experiment
A journey of database full SQL analysis and audit system performance optimization
Esp8266 firmware upgrade method (esp8266-01s module)
私有协议的解密游戏:从秘文到明文
Stm32cubemx learning (I) USB HID bidirectional communication
Dépannage de l'opération cl210openstack - chapitre expérience
The most understandable explanation of coordinate transformation (push to + diagram)
libprint2
2022年G3锅炉水处理复训题库及答案
postman拼接替换参数循环调用接口
Thoroughly understand the "rotation matrix / Euler angle / quaternion" and let you experience the beauty of three-dimensional rotation