feat: 添加健康检查和问候控制器 (#7)

实现新的健康检查端点和Hello控制器以响应GET和POST请求。健康检查返回"ok"或自定义响应,而Hello控制器返回带参数的问候信息。另外,引入了springdoc-openapi以增强API文档生成能力。
This commit is contained in:
suyiiyii 2024-08-10 02:46:54 +08:00 committed by GitHub
parent 4fb6e0566b
commit 3b44def8aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 0 deletions

View File

@ -77,6 +77,11 @@
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,27 @@
package top.suyiiyii.sims.controller;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HealthzController {
@GetMapping("/healthz")
public String healthz() {
return "ok";
}
@PostMapping("/healthz")
public HealthzResponse healthzPost() {
return new HealthzResponse("health");
}
@AllArgsConstructor
@Data
public static class HealthzResponse {
private String status;
}
}

View File

@ -0,0 +1,13 @@
package top.suyiiyii.sims.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello(String username) {
return "Hello " + username;
}
}