I have a controller with two methods. One to delete a user another to remove a user from a role.
@Controller
@RequestMapping(value="/rest/users/**")
public class UsersCtrlr {
@RequestMapping(value="/{username:.+}", method=RequestMethod.DELETE)
public @ResponseBody HttpStatusDoc deleteUser(HttpServletRequest req, @PathVariable String username) {
...
}
@RequestMapping(value="/{username:.+}/roles/{role:.+}", method=RequestMethod.DELETE)
public @ResponseBody HttpStatusDoc deleteUserRole(HttpServletRequest req, @PathVariable String username, @PathVariable String role) {
...
}
}
My front end makes a jquery ajax call with a url as follows:
/rest/users/jdoe@foo.com/roles/some_role
This uri is being mapped to the deleteUser method with a username equal to some_role
I’m trying to get the uri to map to the deleteUserRole and have the username set to jdoe@foo.com and role set to some_role.
Why won’t the uri map to the deleteUserRole?
Does it have something to do with the regular expressions in the RequestMappings?
It is likely because of
**in your class @RequestMapping annotation , your mapping fordeleteUserwill be/rest/users/**/{username:.+}and fordeleteUserRolewill be/rest/users/**/{username:.+}/roles/{role:.+}and the first one will match up to/rest/users/jdoe@foo.com/roles/some_rolepattern. It should work if**is removed from the class @RequestMapping annotation