删除 template/entrance/web/src/main/java/{{.packagePath}}/entrance/web/response/ResponseJsonWebMvcConfiguration.java
fix:删除无用类
This commit is contained in:
@@ -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<HandlerMethodReturnValueHandler> returnValueHandlers = this.requestMappingHandlerAdapter.getReturnValueHandlers();
|
||||
Iterator<HandlerMethodReturnValueHandler> iterator = returnValueHandlers.iterator();
|
||||
List<HandlerMethodReturnValueHandler> 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<HandlerMethodReturnValueHandler> 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) {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user