2012-03-10 91 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) 
相關問題