First of all, I defined a simple POJO as follows:
public class MyDesc {
private String desc;
public MyDesc(String desc) {
setDesc(desc);
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
Then, I passed an instance of MyDesc as Spring MVC Model object:
@Bean
public MyDesc myDesc() {
return new MyDesc("Holla!");
}
@RequestMapping(value="/", method = RequestMethod.GET)
public String home(Model model) {
model.addAttribute("my-desc", myDesc());
return "pages/home";
}
Now, I'd like to show the content into an HTML page by using Thymeleaf as Template Engine.
<div th:text="${my-desc.desc}">Desc placeholder</div>
But an error occurs at runtime:
Property or field 'desc' cannot be found on null
What am I doing wrong?