streaming.controller.SerieController.java Source code

Java tutorial

Introduction

Here is the source code for streaming.controller.SerieController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package streaming.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import streaming.entity.Serie;
import streaming.service.SerieCrudService;

/**
 *
 * @author admin
 */
@Controller
@RequestMapping(value = "/serie")
public class SerieController {

    @Autowired
    private SerieCrudService serieCrudService;

    @RequestMapping(value = "lister", method = RequestMethod.GET)
    public String lister(Model model) {

        Iterable<Serie> listSerie = serieCrudService.findAll();

        model.addAttribute("maListeSerie", listSerie);

        return "serie/listerSerie";
    }

    @RequestMapping(value = "ajouter", method = RequestMethod.GET)
    public String ajouter(Model model) {

        model.addAttribute("maSerie", new Serie());
        return "serie/ajouterSerie";
    }

    @RequestMapping(value = "ajouter", method = RequestMethod.POST)
    public String ajouterPost(@ModelAttribute(value = "maSerie") Serie s) {

        serieCrudService.save(s);

        return "redirect:/serie/lister";
    }

    @RequestMapping(value = "modifier/{idSerie}", method = RequestMethod.GET)
    public String modifier(Model model, @PathVariable(value = "idSerie") long monIdSerie) {
        Serie s = serieCrudService.findOne(monIdSerie);
        model.addAttribute("maSerie", s);
        return "serie/modifierSerie";
    }

    @RequestMapping(value = "modifier", method = RequestMethod.POST)
    public String modifierPost(@ModelAttribute(value = "maSerie") Serie s) {

        serieCrudService.save(s);

        return "redirect:/serie/lister";
    }

    @RequestMapping(value = "supprimer/{idSerie}", method = RequestMethod.GET)
    public String supprimer(@PathVariable(value = "idSerie") long monIdSerie) {
        Serie s = serieCrudService.findOne(monIdSerie);
        serieCrudService.delete(s);
        return "redirect:/serie/lister";
    }

}