//package com.douCasting.config; // //import com.d...

Criado em: 9 de julho de 2026

Respondido usando GPT-5.5 Thinking por Chat01

Pergunta

image.png

//package com.douCasting.config;
//
//import com.douCasting.interceptor.;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.CorsRegistry;
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
//import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
//@Configuration
//public class MywebConfig implements WebMvcConfigurer {
// @Autowired
// private ImageExistInterceptor imageExistInterceptor;
// @Autowired
// private UserInterceptor userInterceptor;
// @Autowired
// private CacheInterceptor cacheInterceptor;
// @Autowired
// private ExplanationInterceptor explanationInterceptor;
// @Autowired
// private CheckWordInterceptor checkWordInterceptor;
// @Autowired
// private ProbationInterceptor probationInterceptor;
//
// /**
// * 拦截器配置
// /
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
// WebMvcConfigurer.super.addInterceptors(registry);
// registry.addInterceptor(imageExistInterceptor).addPathPatterns("/");
// registry.addInterceptor(userInterceptor).addPathPatterns("/
/
.do").excludePathPatterns("/toLogin.do","/buildQRCode.do","/verifyQRCode.do ",
// "/login.do", "/firstLoginByPwd.do", "/logout.do", "/toUserLoginChooseRole.do",
// "/userLoginChooseRole.do", "/actuator/info.do", "/discovery.do", "/getMessageResource.do",
// "/validationOrganization.do", "/validationUser.do", "/validationPersonnel.do", "/statementShow.do",
// "/toOrganizationRegister.do", "/organizationRegister.do", "/clearOrganization.do", "/phoneticism.do",
// "/getVerifyCode.do", "/validateVerifyCode.do", "/ueditor/exec.do", "/saveTemporaryFile.do",
// "/updateUserWithPassWord.do", "/applet/","/newOrganizationRegister.do","/mallEnterpriseRegister.do","/mail/");
// registry.addInterceptor(cacheInterceptor).addPathPatterns("/");
// registry.addInterceptor(explanationInterceptor).addPathPatterns("/
");
// registry.addInterceptor(checkWordInterceptor).addPathPatterns("/");
// // 除登录相关controller、AES加密controller、参数维护相关controller外,其他controller均需判断是否在试用期内
// registry.addInterceptor(probationInterceptor).addPathPatterns("/
/
.do").excludePathPatterns("/toLogin.do",
// "/login.do", "/firstLoginByPwd.do", "/logout.do", "/toUserLoginChooseRole.do",
// "/userLoginChooseRole.do", "/myIndexNavigation.do", "/myIndex.do", "/editChannelTree.do",
// "/insideNewsList.do", "/auditRemind.do", "/getMessageResource.do", "/encrypt.do", "/toCompany.do",
// "/company.do");
// }
//
// // 存在问题:不配置*.do时访问网址可自动跳转,配置*.do后无法跳转,找不到页面
// @Override
// public void addViewControllers(ViewControllerRegistry registry) {
// WebMvcConfigurer.super.addViewControllers(registry);
// // registry.addViewController("/").setViewName("forward:index.jsp");
// // registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
// }
//
// @Override
// public void addCorsMappings(CorsRegistry registry) {
// WebMvcConfigurer.super.addCorsMappings(registry);
// registry.addMapping("/").allowedOrigins("").allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") // 配置跨域请求支持的方式
// .allowCredentials(true)// 配置是否允许发送Cookie,用于 凭证请求, 默认不发送cookie
// .maxAge(3600).allowedHeaders("
");
// }
//}
/

  • 拦截器配置 以上内容导致内容返回不了 需修改拦截器配置
    */
    package com.douCasting.config;

import com.douCasting.interceptor.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Slf4j
@Configuration
public class MywebConfig implements WebMvcConfigurer {
@Autowired
private ImageExistInterceptor imageExistInterceptor;
@Autowired
private UserInterceptor userInterceptor;
@Autowired
private CacheInterceptor cacheInterceptor;
@Autowired
private ExplanationInterceptor explanationInterceptor;
@Autowired
private CheckWordInterceptor checkWordInterceptor;
@Autowired
private ProbationInterceptor probationInterceptor;

text
/** * 拦截器配置 */ @Override public void addInterceptors(InterceptorRegistry registry) { WebMvcConfigurer.super.addInterceptors(registry); // 图片存在检查拦截器 - 拦截所有请求 registry.addInterceptor(imageExistInterceptor).addPathPatterns("/**"); // 用户登录拦截器 - 拦截所有请求(包括 .do 和 /applet/** 等) registry.addInterceptor(userInterceptor) .addPathPatterns("/**") .excludePathPatterns( "/toLogin.do", "/buildQRCode.do", "/verifyQRCode.do", "/login.do", "/firstLoginByPwd.do", "/logout.do", "/toUserLoginChooseRole.do", "/userLoginChooseRole.do", "/actuator/info.do", "/discovery.do", "/getMessageResource.do", "/validationOrganization.do", "/validationUser.do", "/validationPersonnel.do", "/statementShow.do", "/toOrganizationRegister.do", "/organizationRegister.do", "/clearOrganization.do", "/phoneticism.do", "/getVerifyCode.do", "/validateVerifyCode.do", "/ueditor/exec.do", "/saveTemporaryFile.do", "/updateUserWithPassWord.do", "/newOrganizationRegister.do", "/mallEnterpriseRegister.do", "/mail/**" ); // 缓存拦截器 - 拦截所有请求 registry.addInterceptor(cacheInterceptor).addPathPatterns("/**"); // 说明拦截器 - 拦截所有请求 registry.addInterceptor(explanationInterceptor).addPathPatterns("/**"); // 敏感词检查拦截器 - 拦截所有请求 registry.addInterceptor(checkWordInterceptor).addPathPatterns("/**"); // 试用期判断拦截器 - 拦截所有请求(包括 .do 和 /applet/** 等) registry.addInterceptor(probationInterceptor) .addPathPatterns("/**") .excludePathPatterns( "/toLogin.do", "/login.do", "/firstLoginByPwd.do", "/logout.do", "/toUserLoginChooseRole.do", "/userLoginChooseRole.do", "/myIndexNavigation.do", "/myIndex.do", "/editChannelTree.do", "/insideNewsList.do", "/auditRemind.do", "/getMessageResource.do", "/encrypt.do", "/toCompany.do", "/company.do" ); } @Override public void addViewControllers(ViewControllerRegistry registry) { WebMvcConfigurer.super.addViewControllers(registry); } @Override public void addCorsMappings(CorsRegistry registry) { WebMvcConfigurer.super.addCorsMappings(registry); registry.addMapping("/**") .allowedOrigins("*") .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") .allowCredentials(true) .maxAge(3600) .allowedHeaders("*");

}
} 每个拦截器都打印日志然后 这个 注释的之前的东西 都返回给我 一点都不能少 我看下 那个拦截器 返回false了 导致不返回数据

Pensamento

Thought for 21s

Resposta

你现在截图里的接口是:

/applet/getRandom?mobilePhone=15290161737

最可疑的是:你新配置里把 /aplet/**/applet/** 从 userInterceptor 的排除项删掉了,而且 probationInterceptor 也从 /**/*.do 改成了 /**,所以 /applet/getRandom 这种接口现在也会被拦截。下面这版会把每个拦截器进入、返回 true/false、状态码、是否已提交响应都打印出来,方便你直接看是哪个拦截器返回了 false

你可以直接整体替换 MywebConfig.java

java
//package com.douCasting.config; // //import com.douCasting.interceptor.*; //import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.context.annotation.Configuration; //import org.springframework.web.servlet.config.annotation.CorsRegistry; //import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; //import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; // //@Configuration //public class MywebConfig implements WebMvcConfigurer { // @Autowired // private ImageExistInterceptor imageExistInterceptor; // @Autowired // private UserInterceptor userInterceptor; // @Autowired // private CacheInterceptor cacheInterceptor; // @Autowired // private ExplanationInterceptor explanationInterceptor; // @Autowired // private CheckWordInterceptor checkWordInterceptor; // @Autowired // private ProbationInterceptor probationInterceptor; // // /** // * 拦截器配置 // */ // @Override // public void addInterceptors(InterceptorRegistry registry) { // WebMvcConfigurer.super.addInterceptors(registry); // registry.addInterceptor(imageExistInterceptor).addPathPatterns("/**"); // registry.addInterceptor(userInterceptor).addPathPatterns("/**/*.do").excludePathPatterns("/toLogin.do","/buildQRCode.do","/verifyQRCode.do ", // "/login.do", "/firstLoginByPwd.do", "/logout.do", "/toUserLoginChooseRole.do", // "/userLoginChooseRole.do", "/actuator/info.do", "/discovery.do", "/getMessageResource.do", // "/validationOrganization.do", "/validationUser.do", "/validationPersonnel.do", "/statementShow.do", // "/toOrganizationRegister.do", "/organizationRegister.do", "/clearOrganization.do", "/phoneticism.do", // "/getVerifyCode.do", "/validateVerifyCode.do", "/ueditor/exec.do", "/saveTemporaryFile.do", // "/updateUserWithPassWord.do", "/applet/**","/newOrganizationRegister.do","/mallEnterpriseRegister.do","/mail/**"); // registry.addInterceptor(cacheInterceptor).addPathPatterns("/**"); // registry.addInterceptor(explanationInterceptor).addPathPatterns("/**"); // registry.addInterceptor(checkWordInterceptor).addPathPatterns("/**"); // // 除登录相关controller、AES加密controller、参数维护相关controller外,其他controller均需判断是否在试用期内 // registry.addInterceptor(probationInterceptor).addPathPatterns("/**/*.do").excludePathPatterns("/toLogin.do", // "/login.do", "/firstLoginByPwd.do", "/logout.do", "/toUserLoginChooseRole.do", // "/userLoginChooseRole.do", "/myIndexNavigation.do", "/myIndex.do", "/editChannelTree.do", // "/insideNewsList.do", "/auditRemind.do", "/getMessageResource.do", "/encrypt.do", "/toCompany.do", // "/company.do"); // } // // // 存在问题:不配置*.do时访问网址可自动跳转,配置*.do后无法跳转,找不到页面 // @Override // public void addViewControllers(ViewControllerRegistry registry) { // WebMvcConfigurer.super.addViewControllers(registry); // // registry.addViewController("/").setViewName("forward:index.jsp"); // // registry.setOrder(Ordered.HIGHEST_PRECEDENCE); // } // // @Override // public void addCorsMappings(CorsRegistry registry) { // WebMvcConfigurer.super.addCorsMappings(registry); // registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") // 配置跨域请求支持的方式 // .allowCredentials(true)// 配置是否允许发送Cookie,用于 凭证请求, 默认不发送cookie // .maxAge(3600).allowedHeaders("*"); // } //} /** * 拦截器配置 以上内容导致内容返回不了 需修改拦截器配置 */ package com.douCasting.config; import com.douCasting.interceptor.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Slf4j @Configuration public class MywebConfig implements WebMvcConfigurer { @Autowired private ImageExistInterceptor imageExistInterceptor; @Autowired private UserInterceptor userInterceptor; @Autowired private CacheInterceptor cacheInterceptor; @Autowired private ExplanationInterceptor explanationInterceptor; @Autowired private CheckWordInterceptor checkWordInterceptor; @Autowired private ProbationInterceptor probationInterceptor; /** * 拦截器日志包装器: * 用来打印每个拦截器是否进入、preHandle 返回 true/false、响应状态码、响应是否已经提交。 */ private HandlerInterceptor logInterceptor(final String interceptorName, final HandlerInterceptor target) { return new HandlerInterceptor() { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String uri = request.getRequestURI(); String queryString = request.getQueryString(); String method = request.getMethod(); log.info("========== [{}] preHandle 进入 ==========", interceptorName); log.info("[{}] 请求方法: {}", interceptorName, method); log.info("[{}] 请求URI: {}", interceptorName, uri); log.info("[{}] 请求参数: {}", interceptorName, queryString); log.info("[{}] 完整URL: {}", interceptorName, request.getRequestURL()); log.info("[{}] SessionId: {}", interceptorName, request.getRequestedSessionId()); log.info("[{}] Handler: {}", interceptorName, handler); boolean result; try { result = target.preHandle(request, response, handler); } catch (Exception e) { log.error("========== [{}] preHandle 抛出异常 ==========", interceptorName, e); throw e; } log.info("[{}] preHandle 返回结果: {}", interceptorName, result); log.info("[{}] 当前响应状态码: {}", interceptorName, response.getStatus()); log.info("[{}] response.isCommitted(): {}", interceptorName, response.isCommitted()); log.info("[{}] response Content-Type: {}", interceptorName, response.getContentType()); log.info("[{}] response HeaderNames: {}", interceptorName, response.getHeaderNames()); if (!result) { log.warn("!!!!!!!!!! [{}] 返回 false,请重点检查这个拦截器 !!!!!!!!!!", interceptorName); log.warn("[{}] 被拦截请求URI: {}", interceptorName, uri); log.warn("[{}] 被拦截请求参数: {}", interceptorName, queryString); log.warn("[{}] 被拦截请求方法: {}", interceptorName, method); log.warn("[{}] 当前响应状态码: {}", interceptorName, response.getStatus()); log.warn("[{}] response.isCommitted(): {}", interceptorName, response.isCommitted()); } log.info("========== [{}] preHandle 结束 ==========", interceptorName); return result; } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception { try { target.postHandle(request, response, handler, modelAndView); } finally { log.info("========== [{}] postHandle ==========", interceptorName); log.info("[{}] 请求URI: {}", interceptorName, request.getRequestURI()); log.info("[{}] 当前响应状态码: {}", interceptorName, response.getStatus()); log.info("[{}] response.isCommitted(): {}", interceptorName, response.isCommitted()); log.info("[{}] ModelAndView: {}", interceptorName, modelAndView); } } @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception { try { target.afterCompletion(request, response, handler, ex); } finally { log.info("========== [{}] afterCompletion ==========", interceptorName); log.info("[{}] 请求URI: {}", interceptorName, request.getRequestURI()); log.info("[{}] 请求参数: {}", interceptorName, request.getQueryString()); log.info("[{}] 最终响应状态码: {}", interceptorName, response.getStatus()); log.info("[{}] response.isCommitted(): {}", interceptorName, response.isCommitted()); if (ex != null) { log.error("[{}] afterCompletion 捕获异常", interceptorName, ex); } } } }; } /** * 拦截器配置 */ @Override public void addInterceptors(InterceptorRegistry registry) { WebMvcConfigurer.super.addInterceptors(registry); // 图片存在检查拦截器 - 拦截所有请求 registry.addInterceptor(logInterceptor("ImageExistInterceptor", imageExistInterceptor)) .addPathPatterns("/**"); // 用户登录拦截器 - 拦截所有请求(包括 .do 和 /applet/** 等) registry.addInterceptor(logInterceptor("UserInterceptor", userInterceptor)) .addPathPatterns("/**") .excludePathPatterns( "/toLogin.do", "/buildQRCode.do", "/verifyQRCode.do", "/login.do", "/firstLoginByPwd.do", "/logout.do", "/toUserLoginChooseRole.do", "/userLoginChooseRole.do", "/actuator/info.do", "/discovery.do", "/getMessageResource.do", "/validationOrganization.do", "/validationUser.do", "/validationPersonnel.do", "/statementShow.do", "/toOrganizationRegister.do", "/organizationRegister.do", "/clearOrganization.do", "/phoneticism.do", "/getVerifyCode.do", "/validateVerifyCode.do", "/ueditor/exec.do", "/saveTemporaryFile.do", "/updateUserWithPassWord.do", "/newOrganizationRegister.do", "/mallEnterpriseRegister.do", "/mail/**" ); // 缓存拦截器 - 拦截所有请求 registry.addInterceptor(logInterceptor("CacheInterceptor", cacheInterceptor)) .addPathPatterns("/**"); // 说明拦截器 - 拦截所有请求 registry.addInterceptor(logInterceptor("ExplanationInterceptor", explanationInterceptor)) .addPathPatterns("/**"); // 敏感词检查拦截器 - 拦截所有请求 registry.addInterceptor(logInterceptor("CheckWordInterceptor", checkWordInterceptor)) .addPathPatterns("/**"); // 试用期判断拦截器 - 拦截所有请求(包括 .do 和 /applet/** 等) registry.addInterceptor(logInterceptor("ProbationInterceptor", probationInterceptor)) .addPathPatterns("/**") .excludePathPatterns( "/toLogin.do", "/login.do", "/firstLoginByPwd.do", "/logout.do", "/toUserLoginChooseRole.do", "/userLoginChooseRole.do", "/myIndexNavigation.do", "/myIndex.do", "/editChannelTree.do", "/insideNewsList.do", "/auditRemind.do", "/getMessageResource.do", "/encrypt.do", "/toCompany.do", "/company.do" ); } @Override public void addViewControllers(ViewControllerRegistry registry) { WebMvcConfigurer.super.addViewControllers(registry); } @Override public void addCorsMappings(CorsRegistry registry) { WebMvcConfigurer.super.addCorsMappings(registry); registry.addMapping("/**") .allowedOrigins("*") .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") .allowCredentials(true) .maxAge(3600) .allowedHeaders("*"); } }

启动后重新请求:

text
http://localhost:8086/applet/getRandom?mobilePhone=15290161737

然后你重点看控制台有没有类似:

text
!!!!!!!!!! [UserInterceptor] 返回 false,请重点检查这个拦截器 !!!!!!!!!!

或者:

text
!!!!!!!!!! [ProbationInterceptor] 返回 false,请重点检查这个拦截器 !!!!!!!!!!

从你现在这份配置看,大概率是 UserInterceptorProbationInterceptor/applet/getRandom 拦住了。如果确认是它们导致的,恢复接口返回数据时,建议把这两个地方都加上:

java
"/applet/**"

也就是:

java
registry.addInterceptor(logInterceptor("UserInterceptor", userInterceptor)) .addPathPatterns("/**") .excludePathPatterns( ... "/applet/**", ... );

以及:

java
registry.addInterceptor(logInterceptor("ProbationInterceptor", probationInterceptor)) .addPathPatterns("/**") .excludePathPatterns( ... "/applet/**", ... );

Compartilhar esta Q&A