I’m trying to create a simple web-application, which allows users create topics and comment it. The idea was, that after starting a topic, user is redirected to this topic’s page.
@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 topic@ 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);
}
}
But after creating topic i’m receiving error No mapping found for HTTP request with URI [/simpleblog/details/9] in DispatcherServlet with name ‘appServlet’. And I can’t understand what is wrong, because the HTTP-requests are mapped with annotations. And it works with create() and saveNewTopic() functions, but don’t work with the details() function.
The syntax for a path variable is
{foo}, not(foo):