How to pass parameters from view to controller in Spring 3

This is a snippet of my view and when the hyperlink is clicked I need to send two parameters named solicitudId and detailId for the method in the controller

<tr>
    <td>${user.loginName}</td>
    <td>${user.phone}</td>
    <td>${user.address}</td>
    <td><a href="/enable?solicitudId=${user.solicitudId}&detailId=${user.detail}">Enable</a></td>
tr>

      

//controller

@RequestMapping(value="/enable", method=RequestMethod.GET)
    public String enableUser(Model model){
        try{
            //How should I get the values from the parameters solicitudId and detailId?
        }catch(Exception e){
            e.printStackTrace();
        }
        return  null;
}

      

Thanks in advance!

+3


source to share


2 answers


@RequestMapping(value="/enable", method=RequestMethod.GET)
    public String enableUser( @RequestParam("solicitudId") int solicitudId ,   
                              @RequestParam("detailId") int detailId, Model model){
        try{
            //do whatever you want with detailId and solicitudId
        }catch(Exception e){
            e.printStackTrace();
        }
        return  null;
}

      



ref:   http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch16s11.html

+5


source


You need a controller method that accepts an HTTP request object. The parameters will be part of the GET request as name / value pairs. Like this:



Spring MVC controller HTTP GET request parameters

0


source







All Articles