Java – why does the @ requestmapping spring annotation in the controller capture more of what I want?

I have a simple spring controller and mapping:

@Controller
public class HomeController {
@RequestMapping(value = "/home",method = RequestMethod.GET)
    public String home(HttpSession session,HttpServletRequest request,HttpServletResponse response,Model Principal principal) {
        ...
        return "home";
    }
}

It naturally captures http: / / localhost: 18080 / xxx / home, but why does it capture http: / / localhost: 18080 / xxx / home Error or http: / / localhost: 18080 / xxx / home qwe123. 234 wait, I didn't set up home at home Error or home qwe123. 234, etc I only map in my controller How to prevent controller matching?

Solution

Because, by default, spring uses the pathmatchconfigurator to set the MVC environment, and its usesuffixpatternmatch is set to true Start with Javadoc

By having the @ configuration class extend webmvcconfigurationsupport and override it, you can set it to false in the MVC configuration

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
    configurer.setUseSuffixPatternMatch(false);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>