I have a problem when running project. page and controller configure right. But when I add @RequestMapping(value = "/edit/{id}", method = RequestMethod.GET) his throw exception.
NestedServletException: Request processing failed; nested exception is org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public org.springframework.web.servlet.ModelAndView com.solution.controller.BookListController.edit(java.lang.String,org.springframework.ui.Model)]; nested exception is java.lang.IllegalStateException: Could not find @PathVariable [id] in @RequestMapping
Help me. Why this problem is throwed? Page work when I comment "edit" and "delete" methods
My Controller:
@Controller
@RequestMapping("/BookList.vw")
public class BookListController {
@Autowired
private IBookService bookService;
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView openMain(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> model = new HashMap<String, Object>();
List<Book> books = bookService.listBooks();
model.put("books", books);
return new ModelAndView("BookList", "model", model);
}
@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
public ModelAndView edit(@PathVariable String id, Model model) {
Map<String, Object> models = new HashMap<String, Object>();
models.put("id", id);
return new ModelAndView("EditBook", "model", models);
}
@RequestMapping(value = {"/delete/{id}"})
public ModelAndView delete(@PathVariable("id") Integer id) {
bookService.removeBook(id);
return new ModelAndView(getModelName());
}
}
My page fragment:
<c:forEach items="${model.books}" var="book">
<tr align="left" height="100%">
<td>${book.name}</td>
<td>${book.description}</td>
<td>${book.year}</td>
<td></td>
<%--<td>${book.authorNames}</td>--%>
<sec:authorize access="hasRole('ROLE_ADMIN')">
<td>
<a href="${pageContext.request.contextPath}/BookList.vw/edit/${book.id}">Edit</a>
<a href="${pageContext.request.contextPath}/BookList.vw/delete/${book.id}">Delete</a>
</td>
</sec:authorize>
</tr>
</c:forEach>