VB_
VB_

Reputation: 45682

Spring MVC: @ResponseBody Get method return void

I have a controller method which should return some data. I'm wondering why despite it's GET and marked with @ResponseBody it's void.

@ResponseBody    
@RequestMapping(value = "/{id}/data", method = GET)
public void getData(....) { // < Question: how it can be void?
  ....
  dataService.streamData(query); // < this method is also void
}

Question: What spring returns in this case? Is this method useless?

Upvotes: 0

Views: 3953

Answers (1)

Ankur Singhal
Ankur Singhal

Reputation: 26067

If a controller returns a null view name, or declares a void return type, Spring will attempt to infer the view name from the request URL.

It does this using an implementation of RequestToViewNameTranslator, the default implementation of which is DefaultRequestToViewNameTranslator

complete info here

Upvotes: 2

Related Questions