提交 97c88da8 编写于 作者: yubinCloud's avatar yubinCloud

集成 Swagger3 和 Knife 的接口文档,可以通过 `/swagger-ui/` 或者 `/doc.html` 打开

上级 2f85c5f8
......@@ -84,6 +84,18 @@
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>
<dependencyManagement>
......
......@@ -6,7 +6,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;
import springfox.documentation.oas.annotations.EnableOpenApi;
@EnableOpenApi
@SpringBootApplication
@MapperScan("io.github.yubincloud.fairywiki.mapper")
public class FairyWikiApplication {
......
package io.github.yubincloud.fairywiki.config;
import io.swagger.annotations.ApiOperation;
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.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@Configuration
public class Swagger3Config {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Fairy Wiki")
.description("知识库系统")
.contact(new Contact("yubin", "https://github.com/yubinCloud", "yubin_SkyWalker@yeah.net"))
.version("1.0")
.build();
}
}
......@@ -7,11 +7,14 @@ import io.github.yubincloud.fairywiki.dto.resp.ErrorCode;
import io.github.yubincloud.fairywiki.dto.resp.PageRespDto;
import io.github.yubincloud.fairywiki.dto.resp.RestfulModel;
import io.github.yubincloud.fairywiki.service.EbookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
@Api("电子书管理")
@RestController
@RequestMapping("/ebook")
public class EbookController {
......@@ -20,10 +23,10 @@ public class EbookController {
private EbookService ebookService;
/**
* 对 ebook 进行查询的接口
* @param ebookQueryReqDto 查询条件的参数
* @return 查询到的所有ebook
*/
@ApiOperation("对 ebook 进行查询的接口")
@GetMapping("/query")
public RestfulModel<PageRespDto<EbookQueryRespDto>> queryEbooks(@Valid EbookQueryReqDto ebookQueryReqDto) {
PageRespDto<EbookQueryRespDto> bookList = ebookService.queryEbooks(ebookQueryReqDto);
......@@ -33,12 +36,15 @@ public class EbookController {
/**
* 根据请求的参数保存一个 ebook,若id非空则为更新,否则为新增
*/
@ApiOperation(value = "根据请求的参数保存一个 ebook",
notes = "若id非空则为更新,否则为新增")
@PostMapping("/save")
public RestfulModel<Integer> saveEbook(@RequestBody @Valid EbookSaveReqDto ebookSaveReqDto) {
ebookService.save(ebookSaveReqDto);
return new RestfulModel<>(ErrorCode.SUCCESS, "", 0);
}
@ApiOperation(value = "删除一个 ebook")
@DeleteMapping("/delete/{ebookId}")
public RestfulModel<Integer> deleteEbook(@PathVariable Long ebookId) {
ebookService.deleteOneEbook(ebookId);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册