Home > Software design >  Spring Thymeleaf Whitelabel
Spring Thymeleaf Whitelabel

Time:01-19

I was trying to build a simple spring web app. The app works correctly but I am not being able to connect to the web server when using a Thymeleaf template.

The controller class is the following one:

@Controller() public class BookController { 
private final BookRepository bookRepository;
public BookController(BookRepository bookRepository) {
    this.bookRepository = bookRepository;
}

@GetMapping("/books")
public String getBooks(Model model){
    model.addAttribute("bookList", bookRepository.findAll());
    return "books/list";
}
}

The HTML template:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>Spring Web App</title>
</head>
<body>
<h1>Book List</h1>

<table>
    <tr>
        <th>ID</th>
        <th>Title</th>
        <th>Publisher</th>
    </tr>
    <tr th:each="book : ${bookList}">
        <td th:text="${book.id}">123</td>
        <td th:text="${book.title}"> Spring in Action</td>
        <td th:text="${book.isbn}">Wrox</td>
    </tr>
</table>

</body>
</html>

My directory tree is the following one:

Proyect´s Directory Tree

I don´t get any error or exception, I just get the following blank page:

enter image description here

I´ve tried both '@GetMapping' and '@RequestMapping' and followed a few tutorials but i can´t figure out what is the issue. I would be so thankful if someone could help me with this.

I managed to map the error and I only get the status code: enter image description heretry your folder structure like this in the screen short

CodePudding user response:

The problem was that the package controller was over the rest while the IDE interpretated like it was at the same level.

I just had to move the package to the same level and it works.

  • Related