Quick revision
The short answer
When a @Controller method returns "orders/list", Spring MVC treats the String as a view name: the configured ViewResolvers turn it into a View, for example the Thymeleaf template templates/orders/list.html, and the View renders the model into HTML. The prefixes redirect: and forward: change this into a redirect or a server-side forward. A @RestController method returns data instead: its return value is written straight to the response body by a message converter, such as Jackson for JSON, and no view is involved.
What to remember
In this answer, we saw that a @Controller's String return value is a view name: ViewNameMethodReturnValueHandler records it, ViewResolvers such as ThymeleafViewResolver map it to a template using a prefix and suffix, and the View renders the model to HTML. The redirect: prefix sends a 302 and a new browser request, and forward: dispatches the same request internally. A @RestController skips all of this: its return value goes through a message converter chosen by content negotiation and becomes the response body directly.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
When a @Controller method returns "orders/list", Spring MVC treats the String as a view name: the configured ViewResolvers turn it into a View, for example the Thymeleaf template templates/orders/list.html, and the View renders the model into HTML. The prefixes redirect: and forward: change this into a redirect or a server-side forward. A @RestController method returns data instead: its return value is written straight to the response body by a message converter, such as Jackson for JSON, and no view is involved.
Why this question is asked
The same return type, a String, means two completely different things depending on one annotation. Returning "orders/list" from a @Controller renders a page; returning it from a @RestController sends the text orders/list to the browser. Interviewers ask this to check that we understand how Spring MVC decides what to do with a return value. In this answer, we will recap the model and view idea, follow a view name through resolution and rendering, look at the redirect: and forward: prefixes, and then contrast it with how a @RestController writes its response.
1A Quick Recap of Model and View
In a server-rendered application, a controller does two things. It puts data into a model, a map of named values, and it chooses a view, the template that will turn that data into HTML. The controller does not build HTML itself; the template does.
A view name like "orders/list" is just a logical name. It does not say whether the template is Thymeleaf, FreeMarker or JSP, or where it lives. Turning the name into something that can render is the job of a ViewResolver.
2Following the View Name Step by Step
After the method returns, the handler adapter looks for a return value handler that supports a String from a method without @ResponseBody. ViewNameMethodReturnValueHandler takes it and records "orders/list" as the view name, together with the model.
DispatcherServlet then asks its ViewResolvers, in order, to resolve the name. With Spring Boot and Thymeleaf on the classpath, ThymeleafViewResolver is configured with the prefix classpath:/templates/ and the suffix .html, so "orders/list" becomes classpath:/templates/orders/list.html. The resolver returns a View object for that template. If no resolver can find a template, the request fails with an error rather than sending anything.
Finally the View renders: it receives the model, the template engine fills in the values, and the HTML is written to the response with Content-Type text/html. Only at this point is the response body produced.
- Controller returns "orders/list"model holds orders
- ViewNameMethodReturnValueHandlerrecords the view name and the model
- Name starts with redirect: or forward:?Yesbuild a redirect or forwardNoask the ViewResolvers
- ThymeleafViewResolvertemplates/orders/list.html
- View renders the modelHTML written as text/html
5 steps in order. Play them, or step through them one at a time.
3The redirect: and forward: Prefixes
Two prefixes change the meaning of a view name, and they are handled by the URL-based view resolvers before any template lookup. redirect:/orders/7 tells the browser to make a new request: Spring sends a 302 response with a Location header, and the browser then issues GET /orders/7. The model is not carried along, except for flash attributes or values that Spring appends as query parameters.
forward:/orders/7 stays inside the server: the container dispatches the same request to another path, and the browser never knows. The URL in the address bar does not change. We use redirect after a successful form POST, so that a page refresh does not resubmit the form, and forward rarely, mostly for internal routing.
4How a @RestController Differs
@RestController is @Controller plus @ResponseBody on every method. @ResponseBody tells Spring that the return value is the response body itself, not a view name. So RequestResponseBodyMethodProcessor handles the return value instead of the view name handler. It chooses a media type from the Accept header and the method's produces setting, picks a message converter that can write that type, and writes the value directly.
No ViewResolver runs, no template is looked up, and the model is ignored. A returned Order object becomes JSON through the Jackson converter. A returned String goes through StringHttpMessageConverter and is sent as plain text.
| @Controller | @RestController | |
|---|---|---|
| String return value means | a view name | the body text |
| Handled by | ViewNameMethodReturnValueHandler | RequestResponseBodyMethodProcessor |
Uses ViewResolvers | yes | no |
| Uses message converters | no | yes, chosen by Accept |
| Model | rendered by the template | ignored |
| Typical content type | text/html | application/json |
The second method shows the classic mistake in reverse: someone copies a page controller into a @RestController and the browser displays the view name as text.
5Follow-up questions
Can one @Controller class serve both pages and JSON?
Yes. Methods without @ResponseBody return view names, and a method annotated @ResponseBody, or one returning ResponseEntity, writes its value through converters. Mixing them in one class works, but keeping pages and APIs in separate controllers, often under separate paths, is easier to secure and to read.
What happens if a controller returns void or null?
For a @Controller method returning void, Spring derives a default view name from the request path, so GET /orders/list would look for the view orders/list. If the method writes to the HttpServletResponse itself, Spring treats the request as handled. For @ResponseBody methods, void means an empty body with status 200.
What is ContentNegotiatingViewResolver for?
It chooses between several views for the same view name based on the requested media type, for example an HTML template for browsers and a JSON view for API clients. Spring Boot registers it when several view types are present. In modern applications, separate @RestController endpoints usually replace this pattern.
6Conclusion
In this answer, we saw that a @Controller's String return value is a view name: ViewNameMethodReturnValueHandler records it, ViewResolvers such as ThymeleafViewResolver map it to a template using a prefix and suffix, and the View renders the model to HTML. The redirect: prefix sends a 302 and a new browser request, and forward: dispatches the same request internally. A @RestController skips all of this: its return value goes through a message converter chosen by content negotiation and becomes the response body directly.
Open with
In a plain @Controller, a String return value like orders/list is a logical view name. The ViewNameMethodReturnValueHandler records it along with the model, and DispatcherServlet asks the ViewResolvers to resolve it.
Then, if they want more
With Boot and Thymeleaf, ThymeleafViewResolver adds the prefix classpath:/templates/ and the suffix .html, so it finds templates/orders/list.html, and the View renders the model into HTML with text/html. If no template is found, the request fails.
Two prefixes change that. redirect: makes Spring send a 302 with a Location header, so the browser makes a new GET, which is what we do after a form POST to avoid resubmitting on refresh. The model isn't carried, except through flash attributes. forward: dispatches the same request internally to another path, and the browser's URL doesn't change.
A @RestController is @Controller plus @ResponseBody, so the return value is the body itself. RequestResponseBodyMethodProcessor picks a media type from the Accept header and a message converter, Jackson for objects, StringHttpMessageConverter for Strings, and writes it. No view resolvers, no templates, and the model isn't used.
That's why returning orders/list from a REST controller just shows the text orders/list in the browser.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How does Spring MVC resolve a view when a @Controller method returns "orders/list", and...": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/45b5f3f514/