-
Notifications
You must be signed in to change notification settings - Fork 90
Closed
Description
In this project, the following code lead me to a great misunderstanding, I want to share it, and maybe I can help others.
// GreetingController.java
@PostMapping("/greeting")
public String greetingSubmit(@ModelAttribute Greeting greeting) {
return "result";
}
// result.html
<p th:text="'content: ' + ${greeting.content}"/>
At first glance in the result.html, I thought greeting object may refer to the @ModelAttribute Greeting greeting, then I tried to make some modification to use another model OtherModel, but it turned out to be exception.
After google quite a while, I found out that here the ${greeting.content} is linked to the name of the model class rather than the name of the key.
So I believe that the proper way to do this is like this.
@PostMapping("/greeting2")
public String greetingSubmit(@ModelAttribute OtherModel greeting, Model model) {
model.addAttribute("greeting", greeting);
return "result";
}
Thanks
Metadata
Metadata
Assignees
Labels
No labels