增加: 接入Swagger3 [未完成]

This commit is contained in:
TinyAnts
2023-03-14 19:00:36 +08:00
parent eff789eb82
commit 7bc8d4fce1
14 changed files with 154 additions and 36 deletions

View File

@@ -48,15 +48,15 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
@NotNull Object handler) throws Exception {
// 请求方法类型
response.setContentType("application/json;charset=utf-8");
if (!(handler instanceof HandlerMethod)) {
String reqUri = request.getRequestURI();
if (!(handler instanceof HandlerMethod) || !reqUri.startsWith("/api")) {
return HandlerInterceptor.super.preHandle(request, response, handler);
}
// 登录权限校验
try {
response.setContentType("application/json;charset=utf-8");
Method method = this.obtainAop(handler);
String reqUri = request.getRequestURI();
this.checkLogin(method, reqUri);
} catch (LoginException e) {
AjaxResult<Object> result = AjaxResult.failed(e.getCode(), e.getMsg());

View File

@@ -0,0 +1,35 @@
package com.mdd.admin.config;
import com.mdd.common.config.GlobalConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
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())
.enable(true)
.select()
.apis(RequestHandlerSelectors.basePackage("com.mdd.admin.controller"))
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("LikeAdmin【后台】接口文档")
.description("likeadmin快速开发管理后台")
.version(GlobalConfig.version)
.build();
}
}

View File

@@ -23,6 +23,8 @@ spring:
mvc:
static-path-pattern: /api/static/**
throw-exception-if-no-handler-found: true
pathmatch:
matching-strategy: ant_path_matcher
# 数据源配置
datasource:
url: jdbc:mysql://localhost:3306/likeadmin?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false