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()功能,但不能與細節()功能。