当前位置:网站首页>[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
边栏推荐
- 中青杯2022A题高校数学建模竞赛与课程教育思路分析
- Continuous learning of Robotics (Automation) - 2022-
- ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
- termux设置电脑连接手机。(敲打命令贼快),手机termux端口8022
- 杭州电 3711 Binary Number
- 硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
- PHP 实现根据概率抽奖
- Redis源码学习(30),字典学习,dict.h
- 再AD 的 界面顶部(菜单栏)创建常用的快捷图标
- Kotlin Android environment construction
猜你喜欢
SQL injection -day15
QT opens a file and uses QFileDialog to obtain the file name, content, etc
数据的存储
Preprocessing - interpolation
机器人(自动化)课程的持续学习-2022-
tflite模型转换和量化
Gpt-3 is a peer review online when it has been submitted for its own research
Mongo shell, the most complete mongodb in history
Do you choose pandas or SQL for the top 1 of data analysis in your mind?
运算放大器应用汇总1
随机推荐
【mysql】mysql中行排序
POJ培训计划2253_Frogger(最短/floyd)
Opencv third party Library
二进制、八进制、十六进制
AVL树插入操作与验证操作的简单实现
How to write a resume that shines in front of another interviewer [easy to understand]
機器人(自動化)課程的持續學習-2022-
golang 根据生日计算星座和属相
2022 electrician cup a question high proportion wind power system energy storage operation and configuration analysis ideas
SQL injection -day15
Redis source code learning (30), dictionary learning, dict.h
2022夏每日一题(一)
VIM - own active button indent this command "suggestions collection"
如何编写一个程序猿另一个面试官眼前一亮的简历[通俗易懂]
UltraEdit-32 warm prompt: right association, cancel bak file [easy to understand]
史上最全MongoDB之安全认证
[hcie TAC] question 3
Native MySQL
使用 BR 备份 TiDB 集群到 GCS
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)