Controller无法识别正确的处理程序方法

时间:2014-08-20 15:27:31

标签: spring spring-mvc

我有一个控制器,其方法如下:

@Controller
@RequestMapping(value = "/employee/**")
public class EmployeeInfoController{

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView getEmployeeInfoCriteria(@ModelAttribute("employeeInfoParam") EmployeeInfoParam employeeInfoParam) {
            .....
    }

    @RequestMapping(value = "/details/{empId}", method = RequestMethod.GET)
    public ModelAndView getEmployeeDetailsById(@PathVariable String empId) {
            ......
    }
}

我希望每当我/application/employee/时,它都会显示搜索页面。但它没有显示员工详细信息页面,当我提交请求/application/emp/details/101时,它会转到搜索页面而不是详细信息页面。 日志显示如下:

09:45:20,937 INFO  [STDOUT] DEBUG [RequestMappingHandlerMapping:229] - Looking up handler method for path /employee/details/400000000022161
09:45:20,938 INFO  [STDOUT] TRACE [RequestMappingHandlerMapping:267] - Found 2 matching mapping(s) for [/employee/details/400000000022161] : [{[/employee/**],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}, {[/employee/**/details/{empId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}]
09:45:20,939 INFO  [STDOUT] DEBUG [RequestMappingHandlerMapping:234] - Returning handler method [public org.springframework.web.servlet.ModelAndView com.application.web.controller.EmployeeInfoController.getEmployeeInfoCriteria(com.application.web.form.EmployeeInfoParam)]

我的理解是,如果我没有提及任何子网址代替**(这是在班级),则需要getEmployeeInfoCriteria,即/application/employee/。 如果我提及子网址,例如/application/employee/details/1001,则会由getEmployeeDetailsById处理。我在这里缺少什么?

2 个答案:

答案 0 :(得分:2)

无需在类级请求映射中使用**,只需使用

即可

@RequestMapping(value = "/employee/")

答案 1 :(得分:2)

通配符阻止它解析下一个URL。摆脱它。