2012-03-10 90 views
0

我试图创建一个简单的Web应用程序,它允许用户创建主题并对其进行评论。这个想法是,在开始一个主题后,用户被重定向到这个主题的页面。Spring无法找到HTTP请求的映射

@Controller 
public class HomeController { 

    @RequestMapping(value = "/create", method = RequestMethod.GET) 
    public ModelAndView create(Locale locale, Model model) 
    { 
     Topic newTopic = new Topic(); 
     logger.info("HomeControlller: Create"); 
     List<Tag> tagList = newTopic.getTagLict(); 
     Hashtable modelData = new Hashtable(); 
     modelData.put("newTopic", newTopic); 
     modelData.put("tagList", tagList); 

     return new ModelAndView("create", modelData); 

    } 

    @RequestMapping(value = "/create", method = RequestMethod.POST) 
    public String saveNewTopic(@ModelAttribute("newTopic")Topic topic, BindingResult result, Model model) 
    { 
     validate(topic, result); 
     // Go to the "Show [email protected] page 
     return "redirect:details/"+service.saveTopic(topic);  
} 

    @RequestMapping(value = "/details/(topicId)", method = RequestMethod.GET) 
    public ModelAndView details(@PathVariable(value="topicId") int id) 
    { 
      logger.info("HomeControlller: Details: Found a method");   
      Topic topicById = service.findTopicByID((long) id); 
      logger.info("HomeControlller: Details: Performing redirect"); 
      return new ModelAndView("/topic/", "model", topicById); 
    } 


} 

但是创建主题后我收到错误未发现HTTP请求与URI [/ simpleblog /信息/ 9]中的DispatcherServlet名为 'appServlet'映射。而且我不明白什么是错的,因为HTTP请求映射了注释。它与创建()saveNewTopic()功能,但不能与细节()功能。

回答

2

一个路径变量的语法是{foo},不(foo)

@RequestMapping(value = "/details/{topicId}", method = RequestMethod.GET) 
public ModelAndView details(@PathVariable(value="topicId") int id) 
相关问题