i cant seem to access the attributes of the objects passed to the html filein thymeleaf. I am building a spring REST Web application.
CODE IN CONTROLLER
@RequestMapping(value = {"/home/books"}, method = RequestMethod.GET)
public ModelAndView books()
{
ModelAndView modelAndView=new ModelAndView();
Book book =new Book("name","author","id","54");
//book.addBook(book("name","author","id","54"));
List<Book> AllBook =bookService.getAllBooks();
AllBook.add(book);
modelAndView.addObject("books",AllBook);
modelAndView.setViewName("books");
return modelAndView;
}
books.html file in my template
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">
<head>
<title>Books</title>
</head>
<body>
<tr th:each="book: ${books}">
<h1> <td th:text="${book.author}" /></h1>
<td th:text="${book.name}" />
</tr>
</body>
</html>
POJO class
Public class Book implements Serializable{
@Id
private String id;
private String name;
private String author;
private String price;
private int quantity;
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public Book(String name, String author, String id, String price) {
super();
this.name = name;
this.author = author;
this.id = id;
this.price = price;
}
public Book()
{
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
thee web page dosent show the values of book.author or book.name. IT should show name , author.The page itself is responding but no values are shown. This error is shown There was an unexpected error (type=Internal Server Error, status=500). Exception evaluating SpringEL expression: "book.name" (template: "books" - line 11, col 9)
Did i make any mistakes using thymeleaf? please help