Coding interface with Spring controller method with @RequestMapping

I have a controller with the following method:

@RequestMapping(method = POST)
public ModelAndView emailRegister(EmailParameter parameters, ModelMap model) {}

      

Where EmailParameter is an interface. My understanding is that Spring is (magically?) Mapping incoming HTTP parameters to fields of my bean by name, and it can't do that since I declared an interface.

Is it okay to declare an interface here if so there is some additional configuration I need?

I don't have extensive programming experience, so I might be wrong about using the interface type here, but I believe this is what I should be doing?

Also, if anyone can explain how Spring maps request parameters to fields in my object, that would be much appreciated. Or a link to where it is explained as I couldn't find it!

thank

+3


source to share


1 answer


You don't have to use an interface because Spring has to instantiate this object, otherwise you need OR property converters.

Read the following post on how Spring MVC binds a parameter?



Read the "Domain Bind Object" section in the following link.

https://web.archive.org/web/20160516151809/http://www.jpalace.org/document/92/binding-and-validation-of-handler-parameters-in-spring-mvc-controllers

+1


source







All Articles