添加swagger

pull/4/head
guyaojiang 3 years ago committed by 3y
parent 60d783429c
commit 9c968454e1

@ -42,6 +42,16 @@
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
</dependencies>

@ -0,0 +1,52 @@
package com.java3y.austin.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @program: austin
* @description: swagger
* @author: YorickGu
* @create: 2022-01-09 17:22
**/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
// 指定构建api文档的详细信息的方法apiInfo()
.apiInfo(apiInfo())
.select()
// 指定要生成api接口的包路径
.apis(RequestHandlerSelectors.basePackage("com.java3y.austin.controller"))
//使用了 @ApiOperation 注解的方法生成api接口文档
//.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
//可以根据url路径设置哪些请求加入文档忽略哪些请求
.build();
}
/**
* api
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// 标题
.title("Austin")
// 接口描述
.description("Austin")
// 版本信息
.version("1.0")
// 构建
.build();
}
}

@ -4,8 +4,11 @@ import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.java3y.austin.dao.MessageTemplateDao;
import com.java3y.austin.domain.MessageTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -16,6 +19,8 @@ import org.springframework.web.bind.annotation.RestController;
* @author 3y
*/
@RestController
@RequestMapping("/Message")
@Api("发送消息")
public class MessageTemplateController {
@Autowired
@ -25,6 +30,7 @@ public class MessageTemplateController {
* test insert
*/
@GetMapping("/insert")
@ApiOperation("/插入数据")
public String insert() {
MessageTemplate messageTemplate = MessageTemplate.builder()
@ -61,6 +67,7 @@ public class MessageTemplateController {
* test query
*/
@GetMapping("/query")
@ApiOperation("/查找数据")
public String query() {
Iterable<MessageTemplate> all = messageTemplateDao.findAll();
for (MessageTemplate messageTemplate : all) {

@ -96,6 +96,17 @@
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
</dependencyManagement>

Loading…
Cancel
Save