contexts
The MVC framework requests all .do suffixes, but the controller control layer intercepts links without suffixes. If controller requests /111/222, when requesting /111/, it can be entered normally. When we will stock some of the old project (si'huaSpringMVC framework) upgraded to Springboot, found that it can not be accessed, here we are for this piece of the most silky smooth adaptation.
version information
Springboot:2.7.17
programmatic
- 1. Requestor transformation to remove the .do --- except when there are few callers to that system, or few interfaces
- 2, Provider transformation, based on filter or interceptor, redirect after intercepting to .do. --Not recommended, redirection occurs for all do requests
- 3, provider transformation, compatible with .do requests - more silky smooth, recommended 🌟🌟🌟🌟🌟
Option 3 in detail
yaml add suffix function
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
use-suffix-pattern: true
coding side
/**
* @author weipt
* @description accept a (legal) case.dorequesting,non-occurrence302redirects
* @date 2024/9/6 23:09
*/
@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
(".do", );
}
}
self-test
- Write a controller on the backend that intercepts /111/222
- Front-end requests /111/
- If you can get in, it's OK.
expansion
About DispatcherServlet
In traditional MVC, we need to customize the DispatcherServlet and set the intercept path, such as *.do, but after upgrading to Springboot, the DispatcherServlet will be created by default at startup and intercept /**, so we need to customize again the DispatcherServlet, even if it is registered, the logs will prompt, this you can observe
About the @EnableMVC annotation
We have upgraded to Springboot, the annotation is no longer needed, but instead added, will lead to some configuration failure, use with caution.
Help others to the end, send the Buddha to the West.
If the above actions, do not solve your problem, you can contact me:
E-mail address: weipingtao@
Mail title: [Question program consultation] xxxxxx