Spring as @ModelAttribute parameter

I have a UserController with a method:

@RequestMapping(value={"/new"}, method=RequestMethod.GET) public String showCreationForm(@ModelAttribute User user){ return "user_registration_form"; } 

which displays the registration form. I want to keep modularity (it would be nice to use this controller in some other project) in my project, so the User is an interface, and there is its implementation - UserImpl. The problem is that Spring cannot install the user interface. Is there a way to configure Spring to use some standard user implementation?

+4
source share
1 answer

You can provide an object that will be filled with request data using the @ModelAttribute -annotated method:

 @ModelAttribute public User createUser() { return new UserImpl(); } 
+4
source

All Articles