1

This is a simple project where I have tried to practice Thymeleaf and .html relations. Here are the details:

list.html file:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>Spring Framework Simple Sample</title>
</head>
<body>
<h1>Book List</h1>

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

</body>
</html>

in BookController, return path is showing "Cannot Resolve MVC 'view'":

@Controller
public class BookController {

    private final BookRepository bookRepository;

    public BookController(BookRepository bookRepository) {
        this.bookRepository = bookRepository;
    }

    @GetMapping( "/books")
    public String getBooks(Model model){

        model.addAttribute("books", bookRepository.findAll());

        return "books/list";
    }
}

I have tried different thymeleaf dependencies:

<!--        <dependency>-->
<!--            <groupId>org.thymeleaf</groupId>-->
<!--            <artifactId>thymeleaf</artifactId>-->
<!--            <version>3.0.12.RELEASE</version>-->
<!--        </dependency>-->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

I have already tried below links:

Spring boot cannot resolve view page

Spring - Cannot resolve MVC "view" thymeleaf

Spring boot + thymeleaf in IntelliJ: cannot resolve vars

TemplateInputException: Error resolving template ****, template might not exist

https://www.programmersought.com/article/12644906098/

https://spring.io/guides/gs/serving-web-content/

but without any luck. I have read that this is some kind of bug in IntelliJ and tried to do fix it but still not working.

Please, any help and suggestions are welcomed and appreciated in advance for effort.

Path to my .html file:

/home/panda/IdeaProjects/udemyClass/src/main/resources/templates.books/list.html

Ted404
  • 19
  • 5

2 Answers2

1

It seems like your folder wasn't created properly. Look closely at your path: resources/templates.books/list.html

so, in order to make it work:

return "templates.books/list";

or delete this stuff and create the folder in a proper way: delete books folder, and before adding it again, just create any file in templates directory.

Aidos Rustem
  • 145
  • 8
0

@Balthazar thanks for your reply. I have recreated the same path and after it looks like this now:

/home/panda/IdeaProjects/udemyClass/src/main/resources/templates/books/list.html

It is working as expected now.

Ted404
  • 19
  • 5