Reputation: 39
Let's say I have a class Factory
with 2 fields: fName
and fArea
. Is it possible to refer to these fields through a single object f1
(an instance of Factory
) added to either a Model
or a ModelAndView
? Resulting to something like this ${f.fArea}
(where f
is the String attributeName
argument of addObject
method).
Upvotes: 0
Views: 3093
Reputation: 20477
Yes, that's possible. That syntax is the basis of how thymeleaf expressions work...
// Controller
@GetMapping("/whatever")
public String whatever(Map<String, Object> model) {
model.put("f", new Factory());
return "whatever";
}
// Template
</span th:text="${f.fArea}" />
http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#variables
Upvotes: 2