0

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 ?

Manish Gupta
  • 51
  • 1
  • 8
  • is ${li.orderId} resolving correctly on your jsp? Can you post your generated html code for href? – minion Feb 18 '15 at 21:55

1 Answers1

2

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.

Community
  • 1
  • 1
vtor
  • 8,989
  • 7
  • 51
  • 67
  • This can be because of severl reasons. Please check your controller mapping (to be sure that you don't have any mapping, otherwise you have to add it before ```/admin/*```). Also check your MVC configurations. If possible edit your question with more details, so the problem can be catched. – vtor Feb 18 '15 at 20:54
  • all other configuration are ok. my other controller are work fine. – Manish Gupta Feb 18 '15 at 20:57
  • Looks like you still have ``` @RequestMapping("/admin/orderList/${li.orderId}/${confirmed}")``` . Change it to ``` @RequestMapping("/admin/orderList/{orderId}/{confirmed}")``` – vtor Feb 18 '15 at 20:59
  • As you can see in docs and discussions, this is the correct way to build mapping. Sorry but with provided code it is not possible to guess the problem. – vtor Feb 18 '15 at 21:10