Following is a code snippet where we can use @ModelAttribute at method parameter level
@ReqestMapping(value = useruri) public void submitInfo(@ModelAttribute User user) { // Business logic } @ReqestMapping(value = personuri) public void submitInfo(@ModelAttribute Person person) { // Business logic } Can we do like following?
@RequestMapping(value = genericuri) public void submitInfo(HttpServletRequest request, @PathVariable String type) { if (type.equals("user")) { User user = someSpringMvcMethod(request, User.class) } else if (type.equals("person")) { Person person = someSpringMvcMethod(request, Person.class) } //Business logic } Reason is, I am expecting different type of submitted data based on a type and I want to write a generic controller since only difference is conversion of request data to specific java class. User and Person class has lot of different data and I don't think I can use inheritance/polymorphism to solve my use-case here