标签:work ati 删除 mvn fse type ext osi log
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
package com.app.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.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@Configuration
@EnableOpenApi
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.app.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("RESTful APIs")
.description("RESTful APIs")
.termsOfServiceUrl("http://localhost:8080/")
.contact(new Contact("jack", "www.baidu.com", "jack@qq.com"))
.version("1.0")
.build();
}
}
package com.app.controller;
import java.util.logging.Logger;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
@Api(tags = "文章接口")
@RestController
@RequestMapping("/chapter")
public class ArticleController {
Logger logger = Logger.getLogger("com.app.controller.ChapterController");
@ApiOperation(value = "获取指定id的文章", notes = "根据URL的id获取指定文章的信息")
@ApiImplicitParam(name = "id", value = "文章id", required = true, dataType = "Long", dataTypeClass = Long.class)
@GetMapping("/{id}")
public String getOne(@PathVariable Long id) {
logger.info(id + "");
return id + "";
}
@ApiOperation(value = "删除指定id的文章", notes = "根据URL的id删除指定文章的信息")
@ApiImplicitParam(name = "id", value = "文章id", required = true, dataType = "Long", dataTypeClass = Long.class)
@DeleteMapping("/{id}")
public String deleteOne(@PathVariable Long id) {
logger.info(id + "");
return id + "";
}
}
注解说明:
通过访问以下链接进入 swagger 页面。
http://localhost:8080/swagger-ui/index.html#/
Spring Boot 配置 Swagger(3.0.0 版本)
标签:work ati 删除 mvn fse type ext osi log
原文地址:https://www.cnblogs.com/QingXiaxu/p/14638478.html