Solution 1 :

change variable name from film to films in controller:


and in html file :

<li th:each ="film: ${films}">

Problem :

I’m trying to display data from a database in a spring application.

<div class="container-fluid">
    <p>Some text</p>
    <!--/@thymesVar id="film" type="java.util.List<com.example.project1.accessToData.model.Film>"/-->
    <li th:each ="film:${film}">
       <span th_text="${film}"></span>

public FilmIndexControler(FilmService filmService) {
    this.filmService = filmService;

    String showFilms(Model model){
        Iterable<Film> film = filmService.findAll();
        return "index";

public class Film {
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotEmpty(message="Cant be empty")
private String title;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate productionYear;
private String descryption;
@NotEmpty (message="Cant be empty")
private String link}

    public Iterable<Film> findAll () {
    return this.filmRepository.findAll();

When I try to display it on the site, nothing related to the spring happens. I can’t see films in html.


public class FilmApi {

private static final Logger logger = LoggerFactory.getLogger(FilmApi.class);
private final FilmManager filmManager;

public FilmApi(final FilmManager filmManager) {
    this.filmManager = filmManager;


@GetMapping(value = "/lista",params = {"!sort", "!page", "!size"} )
public ResponseEntity<Iterable<Film>> getAll(){
    logger.warn("Lista filmów");
    return ResponseEntity.ok(this.filmManager.findAll());

public ResponseEntity<List<Film>>  findFilm(@Param("title") String title){
    return ResponseEntity.ok(this.filmManager.findFilm(title));

public ResponseEntity<Film> addFilm(@RequestBody Film film){;
    return ResponseEntity.noContent().build();

public ResponseEntity<?> updateFilm(@PathVariable Long id,@RequestBody Film film){
    if (!this.filmManager.exist(id)){
        return  ResponseEntity.notFound().build();
    return ResponseEntity.noContent().build();

public void deleteFilm(@RequestParam Long index){
    if (!this.filmManager.exist(index)){


Ok I added api controller. When I enter localhostapi:8080/api/film/lista, all data is displayed If you need anything else, I will add it soon.


Comment posted by tour

welcome to stackoverflow. Take a

Comment posted by Awros

Still nothing appears

Comment posted by Hemant

Did you debug and see if

Comment posted by Awros

This is probably a problem. If I go to localhost:8080/films it shows me everything from the database, but this method show nothing. I would be grateful if you could direct me where I could make a mistake because I am a beginner in Spring.

Comment posted by Hemant

You must have an api

Comment posted by Awros

Ok, I added this as answer


Leave a Reply

Your email address will not be published. Required fields are marked *