user748554
user748554

Reputation: 11

a question about Spring controller

a piece of code like this:

@Controller  
public class HomeController {
  public static final int DEFAULT_SPITTLES_PER_PAGE = 25;
  private SpitterService spitterService;
  @Inject                     
  public HomeController(SpitterService spitterService) {
    this.spitterService = spitterService;
  }
  @RequestMapping({"/","/home"})        
  public String showHomePage(Map<String, Object> model) {

    model.put("spittles",
              spitterService.getRecentSpittles(DEFAULT_SPITTLES_PER_PAGE));              
    return "home"; 
  }
}

I confused is the servlet know pass what to a method? In this example it pass a Map model to showHomePage, I want to know where is the model from and what contains in the model?

The method not need to pass the model to a view, the servlet will implicitly pass the argument model to view?

Upvotes: 1

Views: 154

Answers (1)

Grooveek
Grooveek

Reputation: 10094

you should study the extended Spring documentation on @RequestMapping

It explains that the String returned by the method will be interpreted as a View name, and the map passed as argument will serve to enrich the model passed to the view

cheers

Grooveek

Upvotes: 1

Related Questions