在Debian系统上查看Swagger文档,通常需要以下几个步骤:
sudo apt update
sudo apt install openjdk-11-jdk
java -version
sudo apt install maven
mvn -version
创建Spring Boot项目:你可以使用Spring Initializr(https://start.spring.io/)来创建一个新的Spring Boot项目,选择必要的依赖,例如springfox-boot-starter
。
引入Swagger依赖:在你的Spring Boot项目的pom.xml
文件中添加Swagger依赖:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
application.yml
或application.properties
文件中配置Swagger:application.yml
:
springfox:
documentation:
swagger-ui:
enabled: true
或application.properties
:
springfox.documentation.swagger-ui.enabled=true
mvn spring-boot:run
http://localhost:8080/swagger-ui/
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api")
@Api(tags = "Sample API")
public class SampleController {
@GetMapping("/hello")
@ApiOperation(value = "Say hello", response = String.class)
public String sayHello() {
return "Hello, World!";
}
@PostMapping("/data")
@ApiOperation(value = "Send data", requestBody = @io.swagger.annotations.ApiRequestBody(content = @io.swagger.annotations.ApiContent(schema = @io.swagger.annotations.ApiSchema(implementation = String.class))), response = String.class)
public String sendData(@RequestBody String data) {
return "Received: " + data;
}
}
请注意,以上步骤是基于Spring Boot项目使用Swagger的常见情况。如果你的项目不是Spring Boot项目,可能需要使用其他方法来查看Swagger文档。