Browse Source

Parametros opcionales

master
Juanjo 1 year ago
parent
commit
3eeed8e39a
4 changed files with 78 additions and 2 deletions
  1. +41
    -2
      src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java
  2. +11
    -0
      src/main/resources/templates/inicio.html
  3. +13
    -0
      src/main/resources/templates/opcionales.html
  4. +13
    -0
      src/main/resources/templates/parametros.html

+ 41
- 2
src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java View File

@ -2,17 +2,56 @@ package es.fp.edu.conecta2.controladores;
import es.fp.edu.conecta2.repo.user.IUserRepo;
import es.fp.edu.conecta2.servicios.UserService;
import io.micrometer.common.util.StringUtils;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class WebControlador {
@GetMapping ("/")
public String prueba() {
return "Esto es una prueba";
public String inicio() {
return "inicio";
}
@RequestMapping("parametros/{a}/{b}/{c}")
public String parametros( @PathVariable int a,
@PathVariable int b,
@PathVariable int c,
Model model) {
model.addAttribute("a",a);
model.addAttribute("b",b);
model.addAttribute("c",c);
return "parametros";
}
@RequestMapping({"opcionales/{a}/{b}/{c}",
"opcionales/{a}/{b}",
"opcionales/{a}",
"opcionales"})
public String opcionales(
@PathVariable (name = "a", required = false) String a,
@PathVariable (name = "b", required = false) String b,
@PathVariable (name = "c", required = false) String c,
Model model) {
if (StringUtils.isEmpty(a)) {
a = "0";
}
if (StringUtils.isEmpty(b)) {
b = "0";
}
if (StringUtils.isEmpty(c)) {
c = "0";
}
model.addAttribute("a",a);
model.addAttribute("b",b);
model.addAttribute("c",c);
return "opcionales";
}
@Autowired


+ 11
- 0
src/main/resources/templates/inicio.html View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
Hola mundo
</body>
</html>

+ 13
- 0
src/main/resources/templates/opcionales.html View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
Parámetros opcionales:
<h1 th:text="${a}">aaaaa</h1>
<h2 th:text="${b}">bbbb</h2>
<h3 th:text="${c}">cccc</h3>
</body>
</html>

+ 13
- 0
src/main/resources/templates/parametros.html View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
</head>
<body>
Parámetros:
<h1 th:text="${a}">aaaaa</h1>
<h2 th:text="${b}">bbbb</h2>
<h3 th:text="${c}">cccc</h3>
</body>
</html>

Loading…
Cancel
Save