Answer the question
In order to leave comments, you need to log in
Why doesn't the call to the model that is defined inside the method work?
Here is an excerpt from the controller:
public ModelAndView profilePage() {
...
Map<String, Object> model = new BindingAwareModelMap();
model.put("general", profileGeneralDTO);
model.put("security", profileSecurityDTO);
return new ModelAndView("profile/profile.html", "profile", model);
}
th:object
? ${general}
and ${secuity}
if I change the method like this:public ModelAndView profilePage(
@AuthenticationPrincipal User user,
Map<String, Object> model
) {
...
// Map<String, Object> model = new BindingAwareModelMap();
model.put("general", profileGeneralDTO);
model.put("security", profileSecurityDTO);
return new ModelAndView("profile/profile.html", "profile", model);
}
model
the same class (BindingAwareModelMap), but now everything works. Why? Answer the question
In order to leave comments, you need to log in
If you are not confused, then it is better to leave it as it works. Are you sure the same method works in both cases?
In general, it is better to use it differently:
@RequestMapping("/subpath")
public String getRequest(Authentication auth, Model model) {
model.put("key", object);
model.put("key2", object2);
return "view.html"; // path to thymeleaf template
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question