Spring mvc app中的404错误

时间:2017-10-22 10:39:56

标签: java spring spring-mvc

我的控制器中有这样的映射:

@RequestMapping(value = "events/newEvent", method = RequestMethod.POST)
public ModelAndView getOrganizerForNewEvent(@RequestParam("id") int organizerId){
    OrganizerEntity organizerEntity = organizerDAOService.findById(organizerId);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("/newEvent");
    modelAndView.addObject("organizer", organizerEntity);
    return modelAndView;
}

webapp ::

中的这种结构

And such structure in webapp:

开发工具请求看起来正确:

In dev tools request looks right

但我收到404错误: But I get 404 error:

我做错了什么?

1 个答案:

答案 0 :(得分:1)

我认为您有错误,因为视图名称不正确

modelAndView.setViewName("/newEvent");

您应该使用不带斜线的名称:

modelAndView.setViewName("newEvent");