From 2c34b38f5867b979ce5b10191937b22b34d91065 Mon Sep 17 00:00:00 2001 From: Spark <2666652@gmail.com> Date: Sat, 12 Oct 2024 00:29:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90web=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../config/MybatisPlusConfiguration.java | 19 ++++++++++ .../aspark/config/SwaggerConfiguration.java | 24 +++++++++++++ .../cc/aspark/config/WebMvcConfiguration.java | 36 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 .gitignore create mode 100644 RollCallServer/src/main/java/cc/aspark/config/MybatisPlusConfiguration.java create mode 100644 RollCallServer/src/main/java/cc/aspark/config/SwaggerConfiguration.java create mode 100644 RollCallServer/src/main/java/cc/aspark/config/WebMvcConfiguration.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/RollCallServer/src/main/java/cc/aspark/config/MybatisPlusConfiguration.java b/RollCallServer/src/main/java/cc/aspark/config/MybatisPlusConfiguration.java new file mode 100644 index 0000000..cebbb24 --- /dev/null +++ b/RollCallServer/src/main/java/cc/aspark/config/MybatisPlusConfiguration.java @@ -0,0 +1,19 @@ +package cc.aspark.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MybatisPlusConfiguration { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } + +} \ No newline at end of file diff --git a/RollCallServer/src/main/java/cc/aspark/config/SwaggerConfiguration.java b/RollCallServer/src/main/java/cc/aspark/config/SwaggerConfiguration.java new file mode 100644 index 0000000..6c43ad9 --- /dev/null +++ b/RollCallServer/src/main/java/cc/aspark/config/SwaggerConfiguration.java @@ -0,0 +1,24 @@ +package cc.aspark.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfiguration { + + // 设置 openapi 基础参数 + @Bean + public OpenAPI customOpenAPI() { + return new OpenAPI() + .info(new Info() + .title("SpringBoot API 管理") + .contact(new Contact().name("spark")) + .version("1.0") + .description("SpringBoot 集成 Knife4j 示例") + .license(new License().name("Apache 2.0"))); + } +} diff --git a/RollCallServer/src/main/java/cc/aspark/config/WebMvcConfiguration.java b/RollCallServer/src/main/java/cc/aspark/config/WebMvcConfiguration.java new file mode 100644 index 0000000..c3c6fc1 --- /dev/null +++ b/RollCallServer/src/main/java/cc/aspark/config/WebMvcConfiguration.java @@ -0,0 +1,36 @@ +package cc.aspark.config; + + +import cc.aspark.interceptor.LoginCheckInterceptor; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * 配置类,注册web层相关组件 + */ +@Configuration +@Slf4j +@EnableWebMvc +@RequiredArgsConstructor +public class WebMvcConfiguration implements WebMvcConfigurer { + + private final LoginCheckInterceptor loginCheckInterceptor; + + /** + * 注册自定义拦截器 + * + * @param registry + */ + @Override + public void addInterceptors(InterceptorRegistry registry) { + log.info("开始注册自定义拦截器..."); + registry.addInterceptor(loginCheckInterceptor) + .excludePathPatterns("/admin/login") + .excludePathPatterns("/admin/register"); + + } +}