1

I have a page with 2 links calling the same Spring controller. Suppose they are both calling this method :

@RequestMapping(value = {"/messages/list"}, method = RequestMethod.GET)
public String viewMessageLogs(ModelMap model) 
{
    return "messageLogs";
}

Each link has a different id value. I need this controller method to somehow be aware of the id of the link the user used to reach it. How could I accomplish that?

Thanks!

Martin
  • 1,977
  • 5
  • 30
  • 67
  • Either use `@RequestParam` or use `@PathVariable` – kakabali Mar 21 '18 at 14:30
  • while the post referenced above isn't exactly what i want (i'm using path variables all over my app) it does provide an alternative. I was hoping not to modify the URL and that the controller could somehow have access to the name of the source link (through the BindingResult for example) but i was able to achieve what i wanted by changing the method annotation to @RequestMapping(value = {"/messages/list-{type}"}, method = RequestMethod.GET) and changing my links accordingly. Thanks – Martin Mar 21 '18 at 14:51
  • that should be fine as it solves your problem? – kakabali Mar 22 '18 at 02:33
  • it's a workaround. I was hoping to achieve this without modifying the URL but indeed it solves my problem – Martin Mar 22 '18 at 12:25
  • Yeap workarounds always help – kakabali Mar 22 '18 at 12:26

0 Answers0