package com.example.demo.controllers; import com.example.demo.models.Actor; import com.example.demo.models.Movie; import com.example.demo.repositories.ActorRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import java.util.HashSet; import java.util.Set; @Controller public class HomeController { @Autowired ActorRepository actorRepository; @RequestMapping("/") public String index(Model model){ // First let's create an actor Actor actor = new Actor(); actor.setName("Sandra Bullock"); actor.setRealname("Sandra Mae Bullowski"); // Now let's create a movie Movie movie = new Movie(); movie.setTitle("Emoji Movie"); movie.setYear(2017); movie.setDescription("About Emojis..."); // Add the movie to an empty list Set movies = new HashSet(); movies.add(movie); // Add the list of movies to the actor's movie list actor.setMovies(movies); // Save the actor to the database actorRepository.save(actor); // Grad all the actors from the database and send them to // the template model.addAttribute("actors", actorRepository.findAll()); return "index"; } }