Skip to content

@RestController avoid declare @RequestBody too [SPR-13868] #18441

Closed
@spring-projects-issues

Description

@spring-projects-issues

Manuel Jordan opened SPR-13868 and commented

Hello

I know that @RestController avoid use or declare @ResponseBody
Just curious if is possible apply for @RequestBody too

Perhaps it should be automatically applied to always for the first parameter of the method. Therefore leaving free to declare other parameters.

I mean from

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value=PersonaRestControllerSupport.ROOT_URI,
                                method=RequestMethod.POST,
                                consumes={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_UTF8_VALUE})
public ResponseEntity<Void> saveOne(@Validated @RequestBody Persona persona){

to (No @RequestBody )

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value=PersonaRestControllerSupport.ROOT_URI,
                                method=RequestMethod.POST,
                                consumes={MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_UTF8_VALUE})
public ResponseEntity<Void> saveOne(@Validated Persona persona){

In case of many parameters in Rest (Perhaps get the URL, or Header) apply something similar about the following (about Parameter order constrains/restrictions)

public String saveOne(@Validated @ModelAttribute Persona persona,
                                    BindingResult result,
                                    RedirectAttributes redirectAttributes){

Where BindingResult must be located after of the Entity Model.

Thanks


Affects: 4.2 GA

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions