FilmController.java 1.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
package com.BDtest.controller;

import java.lang.reflect.Field;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.BDtest.model.Film;
import com.BDtest.repository.FilmRepository;

@Controller
public class FilmController {
	@Autowired
	private FilmRepository repo;
	
	@GetMapping("/films")
	public String showFilms(Model m) {
		m.addAttribute("films",repo.findAll());
		return "films";
	}
	
	
	
	@RequestMapping({"/films/{id}"})
	public String PassFilm (@PathVariable Long id, Model m) {
		
		
		Film film;
		
		film = repo.getById(id);
		
		m.addAttribute("films",film);
		
		return "insertFilms";
	}
	
	@PostMapping({"/films/{id}"})
	public String PassFilm (@PathVariable Long id, @ModelAttribute Film film) {
		
		
		repo.save(film);
		return "redirect:/films";
	}
	
}