Create @ModelAttribute annotation to accept form-data instead of x-www-form-urlencoded

I am using spring webmvc for my project and there I am using @ModelAttribute annotation in controller action to bind form data to model. ModelAttribute binds data fine if I submit data in x-www-form-urlencoded form. But if I am submitting data in simple form data, this is optional.

I am submitting a request using POSTMAN Rest Client, below is the format of my request -

POST /register-school HTTP/1.1
Host: localhost:8080
Accept: application/json
Cache-Control: no-cache

----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="email"

testing@test.com
----WebKitFormBoundaryE19zNvXGzXaLvS5C

      

For this above my request, ModelAttribute does not bind data to the object.

But its work if I send request to x-www-form-urlencoded

POST /register-school HTTP/1.1
Host: localhost:8080
Accept: application/json
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

email=testing%40test.com

      

Is there a way to make ModelAttribute work on form data?

+3


source to share





All Articles