E
E
Eugenue Cesarevich2021-07-14 20:16:34
Java
Eugenue Cesarevich, 2021-07-14 20:16:34

How in the rest-controller to accept form data, which can change the number of fields?

There is a form, the number of fields in which is not fixed, but can change. Moreover, among the fields there are not only string ones, but also for uploading files.

I don't understand how I can accept this heap in the rest controller:

@PostMapping("/test-type-questions")
public ResponseEntity<String> createTestTypeQuestion(@RequestParam Map<String, String> data)

if you do this, then I will lose the ability to read files.

I am using Spring Boot. What should I specify in the request parameters in order to retrieve all the form data later?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-07-14
Hasanly @azerphoenix

Good afternoon.
Usually, there is a separate controller responsible for downloading files. You can create a RestController, to which uploaded files are sent by Ajax, and in the response return the id of the file stored in the database after uploading.
If you decide to implement the way you currently do it, then why not try using a model (DTO). Create a pojo of the desired structure, if there are required fields that must be present, then use spring validation.
If necessary, use ModelMapper or Struts or class Converter<S, T>to convert dto to entity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question