Choose the correct template

Report a typo

Given the following controller, choose a convenient template file.

Java
@Controller
public class WebController {
    private List<Book> booksList = List.of(
        new Book("Spring in action", "Craig Walls"),
        new Book("Clean code", "Robert C. Martin")
    );

    @GetMapping("/books")
    public String books(Model model) {
        model.addAttribute("books", booksList);
        return "books";
    }
}
Kotin
@Controller
class WebController {
    private val booksList = listOf(
        Book("Spring in action", "Craig Walls"),
        Book("Clean code", "Robert C. Martin")
    )

    @GetMapping("/books")
    fun books(model: Model): String {
        model.addAttribute("books", booksList)
        return "books"
    }
}

Templates:

1. books.ftlh

<#list booksList as book>
    <div>
        <h2>${book.title}</h2>
        <p>${book.author}</p>
    </div>
</#list>

2. library.ftlh

<#list books as book>
    <div>
        <h2>${book.title}</h2>
        <p>${book.author}</p>
    </div>
</#list>

3. books.ftlh

<#list books as book>
    <div>
        <h2>${book.title}</h2>
        <p>${book.author}</p>
    </div>
</#list>

4. books.html

<div>
    <h2>Spring in action</h2>
    <p>Craig Walls</p>
</div>
<div>
    <h2>Clean code</h2>
    <p>Robert C. Martin</p>
</div>
Select one option from the list
___

Create a free account to access the full topic