From 2de7183b5f321a9a9add8d37c320a41311cd6c09 Mon Sep 17 00:00:00 2001 From: maxiuxiang Date: Fri, 11 Oct 2024 14:02:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20template/entrance/web/src/?= =?UTF-8?q?main/java/{{.packagePath}}/entrance/web/response/ResponseJsonWe?= =?UTF-8?q?bMvcConfiguration.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix:删除无用类 --- .../ResponseJsonWebMvcConfiguration.java | 69 ------------------- 1 file changed, 69 deletions(-) delete mode 100644 template/entrance/web/src/main/java/{{.packagePath}}/entrance/web/response/ResponseJsonWebMvcConfiguration.java diff --git a/template/entrance/web/src/main/java/{{.packagePath}}/entrance/web/response/ResponseJsonWebMvcConfiguration.java b/template/entrance/web/src/main/java/{{.packagePath}}/entrance/web/response/ResponseJsonWebMvcConfiguration.java deleted file mode 100644 index 004a91d..0000000 --- a/template/entrance/web/src/main/java/{{.packagePath}}/entrance/web/response/ResponseJsonWebMvcConfiguration.java +++ /dev/null @@ -1,69 +0,0 @@ -package {{ .package }}.entrance.web.response; - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.method.annotation.MapMethodProcessor; -import org.springframework.web.method.support.HandlerMethodReturnValueHandler; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; -import org.springframework.web.servlet.mvc.method.annotation.ViewNameMethodReturnValueHandler; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -@Configuration -public class ResponseJsonWebMvcConfiguration implements ApplicationContextAware, WebMvcConfigurer { - private RequestMappingHandlerAdapter requestMappingHandlerAdapter; - private ApplicationContext applicationContext; - - void init() { - List returnValueHandlers = this.requestMappingHandlerAdapter.getReturnValueHandlers(); - Iterator iterator = returnValueHandlers.iterator(); - List newProcessors = new ArrayList<>(); - while (iterator.hasNext()) { - HandlerMethodReturnValueHandler next = iterator.next(); - //在controller中直接返回map,不被默认的MapMethodProcessor拦截 - if (next instanceof MapMethodProcessor || - //在controller中直接返回String,不被默认的ViewNameMethodReturnValueHandler拦截 - next instanceof ViewNameMethodReturnValueHandler) { - } else { - newProcessors.add(next); - } - } - this.requestMappingHandlerAdapter.setReturnValueHandlers(newProcessors); - } - - @Override - public void addReturnValueHandlers(List returnValueHandlers) { - ResponseJsonMethodReturnValueHandler responseJsonMethodReturnValueHandler = new ResponseJsonMethodReturnValueHandler(); - responseJsonMethodReturnValueHandler.afterPropertiesSet(); - returnValueHandlers.add(responseJsonMethodReturnValueHandler); - } - - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } - - @Bean - ServletContextListener listener1() { - return new ServletContextListener() { - @Override - public void contextInitialized(ServletContextEvent sce) { - requestMappingHandlerAdapter = applicationContext.getBean(RequestMappingHandlerAdapter.class); - init(); - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - } - }; - } -}