Various Spring MVC RequestMapping configuration questions

南笙酒味 提交于 2020-01-17 04:20:26

问题


I have several (albeit related) questions about Spring MVC RequestMapping configuration:

  1. Say I have a type-level RequestMapping annotation as follows: @RequestMapping("/root/"). What is the difference between adding this method-level RequestMapping: @RequestMapping(value="leaf") and that one: @RequestMapping(value="/leaf")? Notice the leading slash in second method-level mapping.
  2. What is the difference between having this type-level RequestMapping: @RequestMapping("/root/") and that one @RequestMapping("/root/*")? Notice the star in second mapping.
  3. Say I already have a type-level RequestMapping annotation. How do I override the type-level mapping at the method-level so that the type-level mapping is ignored (for a given controller)?

回答1:


  • It should be same mapping in both cases - /root/leaf for both method level mapping

  • Both are same, in both cases the type level mapping will be combined with the method level mapping to generate the full request path, so type level of /root/* with the method mapping will become /root/leaf - more rules are here - http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/util/AntPathMatcher.html#combine(java.lang.String, java.lang.String)

  • I doubt if you can, type level mapping is combined with method level mapping to create the full path.



来源:https://stackoverflow.com/questions/12712232/various-spring-mvc-requestmapping-configuration-questions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!