当前位置:网站首页>[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
边栏推荐
- 2022 middle school Youth Cup mathematical modeling question B fertility policy research ideas under the background of open three children
- Enter the rough outline of the URL question (continuously updated)
- ggplot 分面的细节调整汇总
- Kotlin Android environment construction
- 【编码字体系列】OpenDyslexic字体
- Redis source code learning (30), dictionary learning, dict.h
- HW notes (II)
- 见到小叶栀子
- 如何检测mysql代码运行是否出现死锁+binlog查看
- HW-小记(二)
猜你喜欢
![[development software] tilipa Developer Software](/img/b8/de2a1ea6474bb3f9b44e7ea01c441b.png)
[development software] tilipa Developer Software

2022 electrician cup question B analysis of emergency materials distribution under 5g network environment

【编码字体系列】OpenDyslexic字体

ggplot 分面的细节调整汇总

Implementation of map and set

超越Postman,新一代国产调试工具Apifox,用起来够优雅

Formation continue en robotique (automatisation) - 2022 -

Antd comment recursive loop comment

机器人(自动化)课程的持续学习-2022-

Ggplot facet detail adjustment summary
随机推荐
EasyUI export excel cannot download the method that the box pops up
Antd comment recursive loop comment
easyui出口excel无法下载框弹出的办法来解决
2022中青杯C题城市交通思路分析
使用 BR 备份 TiDB 集群到 GCS
Use br to back up tidb cluster to GCS
2022夏每日一题(一)
使用 TiDB Lightning 恢复 GCS 上的备份数据
How to detect whether the MySQL code runs deadlock +binlog view
golang 压缩和解压zip文件
QT item table new column name setting requirement exercise (find the number and maximum value of the array disappear)
如何检测mysql代码运行是否出现死锁+binlog查看
Food Chem|深度学习根据成分声明准确预测食品类别和营养成分
Storage of data
Hongmi K40S root gameplay notes
POJ training plan 2253_ Frogger (shortest /floyd)
什么是 CGI,什么是 IIS,什么是VPS「建议收藏」
史上最全学习率调整策略lr_scheduler
Some common software related
[hcie TAC] question 3