当前位置:网站首页>【knife-4j 快速搭建swagger】
【knife-4j 快速搭建swagger】
2022-07-06 21:07:00 【Dotclv】
添加pom依赖
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
添加配置类
@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())
//分组名称
.groupName("3.X版本")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.mingyang.bootlaunch.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
}
添加API 注解
@Api(tags = "文章接口")
@Slf4j
@RestController
public class ArticleController {
/** * 根据id查询文章 * @param id * @return */
@ApiOperation(value = "根据id查询文章")
@ApiImplicitParam(name = "id", value = "文章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);
}
/** * 新增一片文章 */
@ApiOperation(value = "新增一片文章")
@ApiImplicitParam(name = "article", value = "文章实体", required = true, dataType = "Article")
@PostMapping("/article")
private Result addArticle(@RequestBody Article article){
log.info("article:{}", article);
return Result.success(article.getId());
}
/** * 更新一片文章 */
@PutMapping("/article")
@ApiOperation(value = "更新一片文章")
@ApiImplicitParam(name = "article", value = "文章实体", 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());
}
/** * 删除一片文章 * @param id * @return */
@DeleteMapping("/article/{id}")
@ApiOperation(value = "删除一片文章")
@ApiImplicitParam(name = "id", value = "文章id", required = true, dataType = "Long")
private Result deleteArticle(@PathVariable("id") Long id){
log.info("id:{}", id);
return Result.success();
}
}
访问doc.html页面
localhost:9011/doc.html
边栏推荐
猜你喜欢
tflite模型转换和量化
What is Ba? How about Ba? What is the relationship between Ba and Bi?
23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
VHDL implementation of arbitrary size matrix multiplication
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
My brave way to line -- elaborate on what happens when the browser enters the URL
Sub pixel corner detection opencv cornersubpix
Set WiFi automatic connection for raspberry pie
Adaptive non European advertising retrieval system amcad
自适应非欧表征广告检索系统AMCAD
随机推荐
【开发软件】 tilipa开发者软件
Codeworks 5 questions per day (1700 average) - day 7
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
【安全攻防】序列化与反序列,你了解多少?
【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001
[MySQL] row sorting in MySQL
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
浅谈网络安全之文件上传
How to customize the shortcut key for latex to stop running
ubuntu20安装redisjson记录
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
On file uploading of network security
SSL certificate deployment
Lab1 configuration script
codeforces每日5题(均1700)-第七天
qt-线程等01概念
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
预处理——插值
机器学习笔记 - 使用机器学习进行鸟类物种分类
About Confidence Intervals