我有一种情况需要以下RequestMapping:
@RequestMapping(value={"/{section}"})
...method implementation here...
@RequestMapping(value={"/support"})
...method implementation here...
有一个明显的冲突.我希望Spring会自动解决这个问题,并将map / support映射到第二个方法,其他所有内容都放在第一个方法中,但它会映射/支持第一个方法.
我如何告诉Spring允许显式RequestMapping在同一个地方覆盖带有PathVariable的RequestMapping?
编辑2:如果/ support映射出现在/ {section}映射之前,它似乎可以工作.不幸的是,我们有许多控制器包含许多使用RequestMapping的方法.如何确保带有/ {section}映射的控制器最后被初始化?或者预拦截器是否可行?
编辑1:这是简化的,我知道单独使用这两个RequestMapping会没有多大意义)
最佳答案
使用Spring,您可以扩展org.springframework.web.HttpRequestHandler以支持您的方案.
实施方法:
@Override
public void handleRequest(HttpServletRequest request,HttpServletResponse response) throws servletexception,IOException {}
使用它来分析传入的请求,确定请求URL是否是您的特殊请求URL子集的一部分并转发到适当的位置.
例如:
@Override
public void handleRequest(HttpServletRequest request,IOException {
/** You will want to check your array of values and have this data cached **/
if (urlPath.contains("/sectionName")) {
Requestdispatcher requestdispatcher = request.getRequestdispatcher("sections" + "/" + urlPath);
requestdispatcher.forward(request,response);
}
}
并设置您的部分,例如:
@RequestMapping(value={"/sections/{sectionName}"})
这不会干扰任何预先存在的控制器映射.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。