BE study 2nd
After the 1st Study, I have 2 different extra questions.
1. who(which function or class) calls 'public String home(Model model)'?
2. what is Model model?
Let's take a look at it.
public String home(Model model) {
log.info("Handle home request");
model.addAttribute("categories", categoryService.getAllCategories());
return "posts/home";
}
}
This code functions like, giving the 'model' the key-value pair of "categories"- categoryService.getAllCategories() and return posts/home to the View. View get key-value pair of "categories"- categoryService.getAllCategories() in relevantly processed form with relevant posts/home file like posts/home.jsp or posts/home.html.
According to the Gemini,
The framework calls the home method, which logs the request, retrieves categories, and adds them to the Model. It then returns the view template name ("posts/home").
The framework locates and renders the "home.html" template using the data in the Model. This might involve populating elements in the template with the retrieved categories.
Thus, it is likely that the function that calls this function is the router included in the framework(spring), and model is the object that is used to wrap the data of backend to send it to the frontend.
댓글
댓글 쓰기