-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVotanteControlador.java
85 lines (67 loc) · 2.23 KB
/
VotanteControlador.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.example.demo.controlador;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.example.demo.entidades.Votante;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import com.example.demo.servicios.VotanteService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class VotanteControlador {
@Autowired
private VotanteService votanteService;
@GetMapping("/votapp")
public String despVotapp() {
return "/Sprint3";
}
@GetMapping("/pag2")
public String Pag2() {
return "/Sprint3Pág2";
}
@GetMapping("/back")
public String Back() {
return "/Sprint3";
}
@GetMapping("/addVotante")
public String addVotante() {
return "/addVotante";
}
@GetMapping("/listVotante")
public String listarVotantes(Model model) {
try {
List<Votante> listaVotantes = votanteService.findAll();
System.out.println("listaVotantes-->" + listaVotantes.toString());
model.addAttribute("votantes", listaVotantes);
} catch (Exception e) {
System.out.println("error-->" + e.getCause());
}
return "/listVotantes";
}
@GetMapping("/editarVotante/{id}")
public String Editar(@PathVariable int id, Model model) {
Optional<Votante> votante = votanteService.findById(id);
model.addAttribute("votante", votante.get());
return "/modificar";
}
@GetMapping("/eliminarVotante/{id}")
public String Borrar(@PathVariable int id) {
votanteService.deleteById(id);
return "redirect:/listVotante";
}
@GetMapping("/mostrarVotante/{id}")
public String Mostrar(@PathVariable int id, Model model) {
Optional<Votante> votante = votanteService.findById(id);
model.addAttribute("votante", votante.get());
return "/mostrar";
}
@PostMapping("/saveVotante")
public String addVotante(@Validated Votante votante) {
System.out.println("Votante-->"+votante.toString());
votanteService.save(votante);
return "redirect:/listVotante";
}
}