blackpanther
blackpanther

Reputation: 11486

Ensuring that two Request Mapping variables match in Spring MVC

I have the following @RequestMapping within my Spring MVC controller:

@RequestMapping(value = "{personId}/rtbc-{personId}-badge.pdf", method = RequestMethod.GET)
public ModelAndView produceBadgePdf(@PathVariable Integer personId){
    // rest of the code
}

My question is: How can I ensure that the two personIds in the @RequestMapping are matching Integers? Should I just make the variable names differ? Or could I keep the variable names the same?

Upvotes: 2

Views: 393

Answers (1)

David
David

Reputation: 20063

I would change these to seperate integers so you can compare them and end up with the below. Given your example above this should cause no problems and you wouldn't need to edit any client side code of the request either.

@RequestMapping(value = "{personId}/rbc-{secondPersonId}-badge.pdf", method = RequestMethod.GET)
public ModelAndView produceBadgePdf(@PathVariable Integer personId, @PathVariable Integer secondPersonId){
    if(secondPersonId !=null && secondPersonId.equals(personId)) { }
}

Upvotes: 4

Related Questions