0

Among the below two methods, which one gets called first?

      @RequestMapping(method = RequestMethod.POST, params="continue")
        public String save(){
                        }
      @RequestMapping(method = RequestMethod.POST, params="continuesave")
        public String saveReview(){
                        }

Params sent in POST request include:

continue, continuesave="true"

In my local machine, method 1 gets called. But in our prod servers, method 2 is getting called. What is the method calling criteria?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
knix2
  • 327
  • 1
  • 5
  • 19

2 Answers2

0

When I try to run your example, I get an exception java.lang.IllegalStateException: Ambiguous handler methods mapped

By the way, you can change the priority of handlers by negating params(saveReview won't call for both params):

@RequestMapping(method = RequestMethod.POST, params="continue")
public String save(){
    ...
}

@RequestMapping(method = RequestMethod.POST, params={"continuesave"," !continue"})
public String saveReview(){
    ...
}
Dekart
  • 141
  • 1
  • 8
0

You should only map to non overlapping urls. What happens in you case is just undefined behaviour: it may depends on many things and cannot be securely predicted (it even throws an exception in @Dekart test).

Here if both params can be simultaneously present in a request you should have only one mapping and test for the parameters inside the controller method:

  @RequestMapping(method = RequestMethod.POST)
  public String save_req(WebRequest web) {
      Map<String,String[]> param = web.getParameterMap();
      if (...) { // condition for save
          return save();
      }
      else {
          saveReview();
      }
  }

  public String save(){
  }
  public String saveReview(){
  }
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252