You can always do this:
@Controller public class MyController { @Autowired private TicketValidator ticketValidator; @RequestMapping(value="/{companyId}/{userId}/ticket", method=POST) public void createTicket(@RequestBody Ticket newTicket, @PathVariable Long companyId, @PathVariable Long userId) { ticketValidator.validate(newTicket, companyId, userId);
Edit in response to comment:
It does not make sense to check the Ticket regardless of companyId when the fairness of the Ticket depends on the companyId .
If you cannot use the solution above, consider grouping Ticket with companyId into DTO and change the mapping as follows:
@Controller public class MyController { @RequestMapping(value="/{userId}/ticket", method=POST) public void createTicket(@Valid @RequestBody TicketDTO ticketDto, @PathVariable Long userId) {
Esala source share