a question about Spring controller
a piece of code like this:
@Controller
public class HomeController {
publi开发者_如何学编程c 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?
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
精彩评论