我在spring-mvc控制器中有这些方法与这个URL冲突:http://127.0.0.1:7001/deviceApp/device/en/17624
java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://127.0.0.1:7001/deviceApp/device/en/17624':
方法:
@RequestMapping(value = { "/device/{localeParam}/{itemId}", "/device/{localeParam}/{itemId}/{seoURLapplication}"}, method = { RequestMethod.GET })
private String showDeviceDetailsAndSeoURLapplication(@PathVariable String itemId,
@PathVariable String localeParam,
@PathVariable String seoURLapplication,
HttpServletResponse response,
HttpServletRequest request, Model model, Locale locale) {
Item item = deviceService.getItem (Long.parseLong(itemId), "P");
changeLocale (localeParam, request, response);
addItemToModel (item, locale, model);
return DEVICE_DETAIL_VIEW;
}
@RequestMapping(value = { "/device/{localeParam}/{itemId}", "/device/{localeParam}/{itemId}/"}, method = { RequestMethod.GET, RequestMethod.POST })
private String showDeviceDetails(@PathVariable String itemId,
@PathVariable String localeParam,
@ModelAttribute("searchForm") final SearchForm searchForm,
HttpServletResponse response,
HttpServletRequest request, Model model, Locale locale) {
Item item = deviceService.getItem (Long.parseLong(itemId), "P");
return DEVICE_DETAIL_VIEW;
}
web.xml上的
<servlet-mapping>
<servlet-name>deviceWeb</servlet-name>
<url-pattern>/device</url-pattern>
<url-pattern>/device/*</url-pattern>
<url-pattern>/device/*/</url-pattern>
<url-pattern>/device/*/*</url-pattern>
<url-pattern>/device/*/*/*</url-pattern>
</servlet-mapping>
答案 0 :(得分:0)
这两种方法实际上是不明确的,根据您在签名中预期的路径变量,您应该删除"/device/{localeParam}/{itemId}"
showDeviceDetailsAndSeoURLapplication
的映射
另外,servlet映射应该匹配所有请求
<servlet-mapping>
<servlet-name>deviceWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
,或者
<servlet-mapping>
<servlet-name>deviceWeb</servlet-name>
<url-pattern>/device</url-pattern>
</servlet-mapping>
在这种情况下,您应该从控制器映射路径中删除/device