当前位置:网站首页>[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
边栏推荐
- ABAP dynamic inner table grouping cycle
- 如何编写一个程序猿另一个面试官眼前一亮的简历[通俗易懂]
- 运算放大器应用汇总1
- The most complete security certification of mongodb in history
- SSM+jsp实现仓库管理系统,界面那叫一个优雅
- 【开发软件】 tilipa开发者软件
- Termux set up the computer to connect to the mobile phone. (knock the command quickly), mobile phone termux port 8022
- HW notes (II)
- Redis source code learning (30), dictionary learning, dict.h
- 学习使用js把两个对象合并成一个对象的方法Object.assign()
猜你喜欢

The most complete security certification of mongodb in history

数据的存储

AVL树插入操作与验证操作的简单实现

leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
![[hcie TAC] question 3](/img/d2/38a7286be7780a60f5311b2fcfaf0b.jpg)
[hcie TAC] question 3

史上最全MongoDB之部署篇

【系统管理】清理任务栏的已删除程序的图标缓存

Create commonly used shortcut icons at the top of the ad interface (menu bar)

【ArcGIS教程】专题图制作-人口密度分布图——人口密度分析

【写给初发论文的人】撰写综述性科技论文常见问题
随机推荐
Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
别样肉客联手德克士在全国部分门店推出别样汉堡
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
DAB-DETR: DYNAMIC ANCHOR BOXES ARE BETTER QUERIES FOR DETR翻译
The most complete deployment of mongodb in history
Redis source code learning (30), dictionary learning, dict.h
见到小叶栀子
Kotlin Android environment construction
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
The first introduction of the most complete mongodb in history
[MySQL] row sorting in MySQL
数据的存储
2022夏每日一题(一)
The true face of function pointer in single chip microcomputer and the operation of callback function
什么是 CGI,什么是 IIS,什么是VPS「建议收藏」
Kotlin Compose Text支持两种颜色
Unity3d can change colors and display samples in a building GL material
ABAP Dynamic Inner table Group cycle
Top 50 hit industry in the first half of 2022
pyqt5 失焦 监听无操作 定时器