当前位置:网站首页>[knife-4j quickly build swagger]
[knife-4j quickly build swagger]
2022-07-07 04:12:00 【Dotclv】
add to pom rely on
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
Add configuration class
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
@Bean(value = "defaultApi2")
public Docket defaultApi2() {
Docket docket=new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
//.title("swagger-bootstrap-ui-demo RESTful APIs")
.description("# swagger-bootstrap-ui-demo RESTful APIs")
.termsOfServiceUrl("http://www.xx.com/")
.contact(new Contact("ymy", "http://www.xx.com/", "[email protected]"))
.version("1.0")
.build())
// Group name
.groupName("3.X edition ")
.select()
// Designated here Controller Scan package path
.apis(RequestHandlerSelectors.basePackage("com.mingyang.bootlaunch.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
}
add to API annotation
@Api(tags = " Article interface ")
@Slf4j
@RestController
public class ArticleController {
/** * according to id Search article * @param id * @return */
@ApiOperation(value = " according to id Search article ")
@ApiImplicitParam(name = "id", value = " article id", required = true, dataType = "Long")
@GetMapping("/article/{id}")
private Result getArticle(@PathVariable("id") Long id) {
Article article = new Article();
article.setId(id);
article.setTitle("title");
article.setContent("content");
log.info("article:{}", article);
return Result.success(article);
}
/** * Add an article */
@ApiOperation(value = " Add an article ")
@ApiImplicitParam(name = "article", value = " Article entity ", required = true, dataType = "Article")
@PostMapping("/article")
private Result addArticle(@RequestBody Article article){
log.info("article:{}", article);
return Result.success(article.getId());
}
/** * Update an article */
@PutMapping("/article")
@ApiOperation(value = " Update an article ")
@ApiImplicitParam(name = "article", value = " Article entity ", required = true, dataType = "Article")
private Result updateArticle(@RequestBody Article article){
if(article.getId() == null){
return Result.failure(ResultCode.PARAM_ERROR);
}
log.info("article:{}", article);
return Result.success(article.getId());
}
/** * Delete an article * @param id * @return */
@DeleteMapping("/article/{id}")
@ApiOperation(value = " Delete an article ")
@ApiImplicitParam(name = "id", value = " article id", required = true, dataType = "Long")
private Result deleteArticle(@PathVariable("id") Long id){
log.info("id:{}", id);
return Result.success();
}
}
visit doc.html page
localhost:9011/doc.html
边栏推荐
- [record of question brushing] 2 Add two numbers
- 史上最全MongoDB之Mongo Shell使用
- Mysql-数据丢失,分析binlog日志文件
- Mongo shell, the most complete mongodb in history
- 【系统管理】清理任务栏的已删除程序的图标缓存
- 超越Postman,新一代国产调试工具Apifox,用起来够优雅
- 什么是 CGI,什么是 IIS,什么是VPS「建议收藏」
- VIM - own active button indent this command "suggestions collection"
- vim —- 自己主动的按钮indent该命令「建议收藏」
- Storage of data
猜你喜欢
Mysql-数据丢失,分析binlog日志文件
【mysql】mysql中行排序
Summer 2022 daily question 1 (1)
Some common software related
When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
机械臂速成小指南(十):可达工作空间
The most complete security certification of mongodb in history
CUDA Programming
Preprocessing - interpolation
1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
随机推荐
10 ways of interface data security assurance
OSCP工具之一: dirsearch用法大全
Redis configuration and optimization of NoSQL
SQL injection -day15
Operational amplifier application summary 1
链表面试常见题
机器学习笔记 - 使用机器学习进行鸟类物种分类
2022 electrician cup a question high proportion wind power system energy storage operation and configuration analysis ideas
Pyqt5 out of focus monitoring no operation timer
见到小叶栀子
Create commonly used shortcut icons at the top of the ad interface (menu bar)
Force buckle ----- path sum III
pyqt5 失焦 监听无操作 定时器
DAB-DETR: DYNAMIC ANCHOR BOXES ARE BETTER QUERIES FOR DETR翻译
Do you choose pandas or SQL for the top 1 of data analysis in your mind?
Analysis on urban transportation ideas of 2022 Zhongqing cup C
2022 middle school Youth Cup mathematical modeling question B fertility policy research ideas under the background of open three children
[record of question brushing] 2 Add two numbers
SSM+jsp实现仓库管理系统,界面那叫一个优雅
QT item table new column name setting requirement exercise (find the number and maximum value of the array disappear)