You can set both mapping url for the same function and setting id as optional.
@RequestMapping(method=RequestMethod.GET, value={"/campaigns","/campaigns/{id}"})
public String getCampaignDetails(Model model,
@RequestParam(value="id", required=false) Long id,
@PathVariable("id") Long id2)
{
}
though it would map as well when id is not sent, but you can control this inside the method.
EDIT: The previous solution doesn’t work because @PathVariable is not set to null when there isn’t {null} and it cannot map the URL (thanks ngeek). I think then that the only possible solution is to create two methods each one mapped with its @MappingRequest and inside one of them call the other function or redirect to the other URL (redirect: or forward: Spring prefixes). I know this solution is not what you’re looking for but think it’s the best you can do. Indeed you’re not duplicating code but you’re creating another function to handle another URL.