From a70919b4f7baab856125f36e5bd41f5ee81be680 Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期二, 13 五月 2025 09:41:35 +0800 Subject: [PATCH] 修改年份切换字段不为必填 --- src/main/java/com/cl/config/WebMvcConfiguration.java | 122 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 122 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/cl/config/WebMvcConfiguration.java b/src/main/java/com/cl/config/WebMvcConfiguration.java new file mode 100644 index 0000000..ac1d3bd --- /dev/null +++ b/src/main/java/com/cl/config/WebMvcConfiguration.java @@ -0,0 +1,122 @@ +package com.cl.config; + + + +import com.cl.common.json.JacksonObjectMapper; +import com.cl.interceptor.JwtTokenInterceptor; +import com.cl.util.LoginAttemptService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.schema.ModelRef; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Parameter; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +import java.util.ArrayList; +import java.util.List; + +/** + * 配置类,注册web层相关组件 + */ +@Configuration +@Slf4j +public class WebMvcConfiguration extends WebMvcConfigurationSupport { + + @Autowired + private JwtTokenInterceptor jwtTokenInterceptor; + + + + /** + * 注册自定义拦截器 + * + * @param registry + */ + protected void addInterceptors(InterceptorRegistry registry) { + log.info("开始注册自定义拦截器..."); + registry.addInterceptor(jwtTokenInterceptor) + .addPathPatterns("/user/**","/data/**","/institution/**") + .excludePathPatterns("/user/login","user/loginOut","/user/passwordBeforeLogin","/data/screen", + "/institution/getAll/**","/data/getYearList","/data/getAssistiveDeviceTotal"); + } + + /** + * 通过knife4j生成接口文档 + * @return + */ + @Bean + public Docket docket() { + ApiInfo apiInfo = new ApiInfoBuilder() + .title("残联大屏项目接口文档") + .version("3.0") + .description("残联大屏项目接口文档") + .build(); + // 定义请求头参数 + ParameterBuilder tokenParamBuilder = new ParameterBuilder(); + tokenParamBuilder.name("token") // 参数名 + .description("请求头token") // 描述 + .modelRef(new ModelRef("string")) + .parameterType("header") // 参数类型为请求头 + .required(false) // 是否必填 + .build(); + List<Parameter> parameters = new ArrayList<>(); + parameters.add(tokenParamBuilder.build()); + Docket docket = new Docket(DocumentationType.SWAGGER_2) + + .select() + .apis(RequestHandlerSelectors.basePackage("com.cl.controller")) + .paths(PathSelectors.any()) + .build() + .globalOperationParameters(parameters) + .apiInfo(apiInfo); // 全局设置请求头参数; + return docket; + } + + + /** + * 设置静态资源映射 + * @param registry + */ + protected void addResourceHandlers(ResourceHandlerRegistry registry) { + // For Springfox 3.x + registry.addResourceHandler("/swagger-ui/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/") + .resourceChain(false); + + } + + /** + * 扩展Spring MVC框架的消息转换器 + * @param converters + */ + @Override + protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) { + log.info("扩展消息转换器"); + //创建一个消息装换器对象 + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + //需要为消息转换器设置一个对象转换器,对象装换器可以将java对象序列化为json数据 + converter.setObjectMapper(new JacksonObjectMapper()); + //将自己的消息转换器加入到容器中 + converters.add(0,converter); + } + + /** + * 登录密码错误次数校验 + */ + @Bean + public LoginAttemptService loginAttemptService() { + return new LoginAttemptService(); + } +} \ No newline at end of file -- Gitblit v1.7.1