How DefaultAnnotationHandlerMapping works

前端 未结 1 692
既然无缘
既然无缘 2021-01-01 03:06

I am confused about the way the DefaultAnnotationHandlerMapping works.

In my web.xml I have

 
    spring&l         


        
相关标签:
1条回答
  • 2021-01-01 03:36

    Spring will match against the pathInfo property of the HttpServletRequest.

    If your web.xml specifies <url-pattern>/user/*</url-pattern>, then the pathInfo will be the path with the /user prefix removed, so the @RequestMapping has to be /adduser.

    If web.xml specifies <url-pattern>/user/adduser</url-pattern>, then the pathInfo will be the full /user/adduser path, so @RequestMapping has to match against that.

    This isn't done by Spring, but by the servlet container, and it can be a bit confusing at times.

    You can mitigate against this by using wildcards in @RequestMapping, e.g.

    @RequestMapping(value="**/adduser", method={RequestMethod.POST})
    
    0 讨论(0)
提交回复
热议问题