mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-14 02:57:11 +08:00
新增:新增接口文档配置(基于 Spring Doc OpenAPI,使用 Knife4j 作为增强解决方案)
This commit is contained in:
@@ -18,18 +18,23 @@ package top.charles7c.cnadmin;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import top.charles7c.cnadmin.common.config.properties.ContinewAdminProperties;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
@@ -39,22 +44,16 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@SpringBootApplication
|
||||
@RequiredArgsConstructor
|
||||
@Import(cn.hutool.extra.spring.SpringUtil.class)
|
||||
@ComponentScan(basePackages = {"top.charles7c.cnadmin", "cn.hutool.extra.spring"})
|
||||
public class ContinewAdminApplication {
|
||||
public class ContinewAdminApplication implements ApplicationRunner {
|
||||
|
||||
private static Environment env;
|
||||
private final ContinewAdminProperties properties;
|
||||
private final ServerProperties serverProperties;
|
||||
|
||||
@SneakyThrows
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(ContinewAdminApplication.class);
|
||||
ConfigurableApplicationContext context = application.run(args);
|
||||
|
||||
env = context.getEnvironment();
|
||||
log.info("------------------------------------------------------");
|
||||
log.info("{} backend service started successfully.", env.getProperty("continew-admin.name"));
|
||||
log.info("后端 API 地址:http://{}:{}", InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"));
|
||||
log.info("------------------------------------------------------");
|
||||
SpringApplication.run(ContinewAdminApplication.class, args);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,8 +61,19 @@ public class ContinewAdminApplication {
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@Hidden
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
return String.format("%s backend service started successfully.", env.getProperty("continew-admin.name"));
|
||||
return String.format("%s backend service started successfully.", properties.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
String hostAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
log.info("------------------------------------------------------");
|
||||
log.info("{} backend service started successfully.", properties.getName());
|
||||
log.info("后端 API 地址:http://{}:{}", hostAddress, serverProperties.getPort());
|
||||
log.info("后端 API 文档:http://{}:{}/doc.html", hostAddress, serverProperties.getPort());
|
||||
log.info("------------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,10 @@ import java.time.Duration;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -39,18 +43,15 @@ import top.charles7c.cnadmin.common.util.RedisUtils;
|
||||
* @author Charles7c
|
||||
* @since 2022/12/11 14:00
|
||||
*/
|
||||
@Tag(name = "验证码 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/captcha")
|
||||
@RequestMapping(value = "/captcha", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public class CaptchaController {
|
||||
|
||||
private final CaptchaProperties captchaProperties;
|
||||
|
||||
/**
|
||||
* 获取图片验证码
|
||||
*
|
||||
* @return 验证码信息
|
||||
*/
|
||||
@Operation(summary = "获取图片验证码", description = "获取图片验证码(Base64编码,带图片格式:data:image/gif;base64)")
|
||||
@GetMapping("/img")
|
||||
public R<CaptchaVO> getImageCaptcha() {
|
||||
// 生成验证码
|
||||
|
Reference in New Issue
Block a user