Spring Controller receive parameter form

receive parameters from the front end (APP or other separate front end) in SpringMVC, usually in the form (valued by request.getParameters (xxx)) or directly from the Json object?
which is more convenient?

Jul.09,2021

for convenience, that must be json. Otherwise, how many fields do you need to write? how many get


look at the answer above, you still need to edit it.
first of all, if you can get the parameters using request.getParameters , it means that the json, is not sent from the client because json cannot get it with request.getParameter . Secondly, it does no harm to connect parameters directly with objects (unless there are only one or two parameters, but even if there are few parameters, you can directly use @ RequestParam without manually removing them from request)
if you still insist on request.getParameter with SpringMVC,. Or very familiar with these things, it is better to know everything directly getParameters; Or it is not familiar enough to know that the framework has a convenient function to obtain parameters


@ ModelAttribute take request.param, @ RequestBody take request.content.
both can be followed by an object. @ ModelAttribute can also take values from other places (such as redis) through custom methods, along with binding=false to avoid taking values from parameters.

Menu