Spring MVC HTTP Controller GET Request Parameters

How can I, without annotations, create and connect a controller that will perform an action based on a request parameter?

So maybe I have a page with a list of elements on it, and each of them is a link, for example, edititem.htm? id = 5. When the user clicks on the link, I want the controller to upload "item number 5" and submit it to my edit form.

I apologize for such a stupid question, but for some reason I cannot find an example of this online service.

+6
java spring-mvc
source share
1 answer

You must have a controller that maps to edititem.htm. (Maybe SimpleFormController )

Override one of the two showForm methods to populate your model with an element:

protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors){ //get the id int id = Integer.parseInt(request.getParameter("id")); // get the object Item item = dao.getItemById(id); return new ModelAndView(getFormView(), "item", item); } 

Also see Various Views with Forms Spring

+6
source

All Articles