liveBook · Manning

View

As explained in Spring Start Here, Second Edition

A view is the presentation resource whose content is rendered and returned as a web response.

A view is the page content rendered for a web response. A controller action returns a view name; the DispatcherServlet asks a View Resolver for the matching view, then returns its rendered content. Spring Boot configures these components, leaving application code to define controller actions. For REST endpoints, use @ResponseBody or @RestController; otherwise, Spring assumes the method returns a view name. section 7.3 section 10.6

Listing 7.5 The definition of the controller class
@Controller    #A
public class MainController {
 
  @RequestMapping("/home")  #B
  public String home() {
    return "home.html";    #C
  }
}

This controller maps /home to the view name home.html, illustrating how a controller selects a view for rendering. section 7.3

How Spring Start Here, Second Edition covers it

How deep it goes
Traces request dispatch through the controller and view resolver, while deferring HTTP-method details.
Examples
Uses a static home.html page with a Welcome heading, selected by a controller action.
What you can do after
Understand how Spring MVC resolves a controller's view name into content returned in an HTTP response.
How it connects
Connects views with controllers, handler mappings, view resolvers, and REST response bodies.

Also explained in

Compare how 8 books explain view →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.