我有一个视图解析器:
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("WEB-INF/jsp/");
resolver.setSuffix(".jsp");
return resolver;
}
和一个控制器:
@Controller
public class WorkflowListController {
@RequestMapping(path = "/workflowlist", method = RequestMethod.GET)
public ModelAndView index() throws LoginFailureException, PacketException,
NetworkException {
String profile = "dev";
List<WorkflowInformation> workflows = workflows(profile);
Map<String, Object> map = new HashMap<String, Object>();
map.put("profile", profile);
map.put("workflows", workflows);
return new ModelAndView("workflowlist", map);
}
}
当我调用该页面时http://127.0.0.1:8090/workflowlist
,它会从src/main/webapp/WEB-INF/jsp/workflowlist.jsp
. 这一切似乎运作良好。
但是,当我尝试添加一个@PathVariable
:
@RequestMapping(path = "/workflowlist/{profile}", method = RequestMethod.GET)
public ModelAndView workflowlist(@PathVariable String profile)
throws LoginFailureException, PacketException, NetworkException {
List<WorkflowInformation> workflows = workflows(profile);
Map<String, Object> map = new HashMap<String, Object>();
map.put("profile", profile);
map.put("workflows", workflows);
return new ModelAndView("workflowlist", map);
}
当我调用该页面时http://127.0.0.1:8090/workflowlist/dev
,会显示以下消息:
There was an unexpected error (type=Not Found, status=404).
/workflowlist/WEB-INF/jsp/workflowlist.jsp
有人可以解释为什么我在两种情况下都返回相同的视图名称,但在第二个示例中它的行为不同?
我怎样才能让它工作?