Manish Gupta
Manish Gupta

Reputation: 51

Two parameter in Request mapping

I have problem with request mapping with two parameters in spring MVC controller.

             /* Jsp page code*/

<c:url var="url_confirm" value="/admin/orderList"/>
<a href="${url_confirm}/${li.orderId}/${"confirmed"}" >Confirmed</a>

and in my Controller i am trying like this but i got error:-

@RequestMapping("/admin/orderList/${li.orderId}/${"confirmed"}")
public String changeStatus(@RequestParam("li.orderId") Integer orderId,@RequestParam("confirmed") String status) {

      // TODO
    System.out.println(orderId);
    System.out.println(status);
    return "orderList";
}

how i can map URL correctly with two parameter for get both value(orderId ,status) at controller ?

Upvotes: 0

Views: 3047

Answers (1)

vtor
vtor

Reputation: 9309

In this case you need @PathVariable not, @RequestParam. So change your mapping to,

@RequestMapping("/admin/orderList/{orderId}/{confirmed}")
public String changeStatus(@PathVariable("orderId") Integer orderId, @PathVariable("confirmed") String status) {

   // your code here
}

For more details, comparison take a look at this topic.

Upvotes: 2

Related Questions