Reputation: 5452
I am new to Spring MVC and trying to list some data on the view by using Thymeleaf
Controller
@RequestMapping("/booksWithMultipleAuthors")
public String booksWithMultipleAuthors(Model model) {
model.addAttribute("booksWithMultipleAuthors", this.userService.getAllWithAuthors());
return "booksWithMultipleAuthors";
}
View:
<div th:each="author : *{authors}" th:object="${author}">
<a th:text="${author.name}">Author name:</a>
</div>
I am able to list books but when it comes to list authors i am getting HTTP Status 500 - Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.standard.processor.attr.StandardEachAttrProcessor' (booksWithMultipleAuthors)
error. How do i fix this ?
Upvotes: 1
Views: 5581
Reputation: 1354
The attribute name you are adding to the model does not match the object you are trying to access in your view.
Controller:
@RequestMapping("/booksWithMultipleAuthors")
public String booksWithMultipleAuthors(Model model) {
model.addAttribute("authors", this.userService.getAllWithAuthors());
return "booksWithMultipleAuthors";
}
View:
<div th:each="author : ${authors}">
<a th:text="${author.name}">Author name:</a>
</div>
Upvotes: 1