我正在使用基本的javascript重定向到页面:
window.location = "handleMyPage.ctl?myNewParameter=1234";
但是,当控制流(正确)到达我的控制器时,请求将由另一个(错误)函数处理。
我的函数的注释方式如下:
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, params={"somePreExisingParameterIAmNotUsing"})
protected ModelAndView otherHandler(HttpServletRequest request, HttpServletResponse response) {
log.info("This gets called for some reason!");
}
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, params={"myNewParameter"})
protected ModelAndView handlerIActuallyWantCalled(HttpServletRequest request, HttpServletResponse response) {
log.info("this never gets called?");
}
我已经在服务器端检查了请求-我可以看到parameterMap仅包含“ myNewParameter”,而没有“ somePreExisingParameterIAmNotUsing”的踪迹-但是引用somePreExisingParameterIAmNotUsing的函数仍然是唯一被调用的函数。
值得注意的是,somePreExisingParameterIAmNotUsing也是引用的第一个函数-因此,我相信请求分派器可能只是默认使用第一个函数...
我知道window.location =只会触发GET HTTP动词-但现在我可以接受-方法= {RequestMethod.GET,RequestMethod.POST}应该可以解决这个问题?
当它是GET请求时,param在requestMapping中不起作用吗?
答案 0 :(得分:0)
确定了我要提交的问题。
我的控制器原来很旧:它正在扩展AbstractController-这是模板方法设计模式的实现。
因此,Spring正在寻找期望实现的特定函数名称,而不使用我的注释。
因此,由于在代码历史记录中的某个时刻,有人出现并添加了注释,而没有删除旧的继承的请求映射方法-未能意识到,因为只有一个控制器功能,注释没有执行任何操作。
解决方案是删除extends AbstractController
引用,并确保为控制器配置了注释。