@ -0,0 +1,21 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project version="4"> | |||
<component name="CompilerConfiguration"> | |||
<annotationProcessing> | |||
<profile name="Maven default annotation processors profile" enabled="true"> | |||
<sourceOutputDir name="target/generated-sources/annotations" /> | |||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> | |||
<outputRelativeToContentRoot value="true" /> | |||
<module name="alejandro-prueba" /> | |||
</profile> | |||
</annotationProcessing> | |||
<bytecodeTargetLevel> | |||
<module name="alejandro-prueba" target="17" /> | |||
</bytecodeTargetLevel> | |||
</component> | |||
<component name="JavacSettings"> | |||
<option name="ADDITIONAL_OPTIONS_OVERRIDE"> | |||
<module name="alejandro-prueba" options="-parameters" /> | |||
</option> | |||
</component> | |||
</project> |
@ -0,0 +1 @@ | |||
dss |
@ -0,0 +1,13 @@ | |||
package com.example.demo; | |||
import org.springframework.boot.SpringApplication; | |||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||
/* Equivalente a : @Configuration + @EnableAutoConfiguration + @ComponentScan = @SpringBootApplication */ | |||
@SpringBootApplication | |||
public class DemoApplication { | |||
public static void main(String[] args) { | |||
SpringApplication.run(DemoApplication.class, args); | |||
} | |||
} |
@ -0,0 +1,111 @@ | |||
package com.example.demo; | |||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | |||
import java.net.InetAddress; | |||
import java.net.MalformedURLException; | |||
import java.net.URL; | |||
import java.net.UnknownHostException; | |||
import static java.net.IDN.toASCII; | |||
import static java.net.IDN.toUnicode; | |||
public class Dominio { | |||
String host; | |||
String protocolo; | |||
String dominio; | |||
String tld; | |||
int puerto; | |||
String addr; | |||
byte[] address; | |||
String canonnical; | |||
String hostname; | |||
String url; | |||
String path; | |||
String error; | |||
String query; | |||
public Dominio() throws MalformedURLException { | |||
final String currentURL = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString(); | |||
URL requestURL = new URL(currentURL); | |||
this.puerto = requestURL.getPort(); | |||
this.host = requestURL.getHost(); | |||
this.protocolo = requestURL.getProtocol(); | |||
this.path = requestURL.getPath(); | |||
this.query = requestURL.getQuery(); | |||
/* información del servidor */ | |||
InetAddress iaddr=null; | |||
String hostnameCanonical=null; | |||
String hostname=null; | |||
byte[] address=null; | |||
try { | |||
iaddr = InetAddress.getByName(InetAddress.getLocalHost().getHostName()); | |||
this.addr = iaddr.toString(); | |||
this.canonnical = iaddr.getCanonicalHostName(); | |||
this.address = iaddr.getAddress(); | |||
this.hostname = iaddr.getHostName(); | |||
} catch (UnknownHostException e) { | |||
this.error="UnknownHostException"; | |||
} | |||
this.url = currentURL; | |||
//Eliminamos www si existen | |||
this.url = url.replace("www.",""); | |||
//Buscamos el primer . (http://eldominio.****** | |||
int y=url.indexOf('.'); | |||
if (y==-1) { | |||
this.dominio= "sin-dominio"; | |||
this.tld = "sin-tld"; | |||
} | |||
else { | |||
this.dominio = toUnicode(url.substring(url.indexOf("://")+3,y)); | |||
this.tld = url.substring(y).replace(":"+this.puerto,""); | |||
} | |||
} | |||
public String getError() { | |||
return error; | |||
} | |||
public String getAddr() { | |||
return addr; | |||
} | |||
public byte[] getAddress() { | |||
return address; | |||
} | |||
public String getCanonnical() { | |||
return canonnical; | |||
} | |||
public String getHostname() { | |||
return hostname; | |||
} | |||
public String getHost() { | |||
return host; | |||
} | |||
public String getUrl() { | |||
return url; | |||
} | |||
public String getPath() { | |||
return path; | |||
} | |||
public String getQuery() { | |||
return query; | |||
} | |||
public String getProtocolo() { | |||
return protocolo; | |||
} | |||
public String getDominio() { | |||
return dominio; | |||
} | |||
public String getTld() { | |||
return tld; | |||
} | |||
public int getPuerto() { | |||
return puerto; | |||
} | |||
} |
@ -0,0 +1,46 @@ | |||
package com.example.demo.controllers; | |||
import com.example.demo.models.Empleado; | |||
import com.example.demo.services.EmpleadoServicio; | |||
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.PostMapping; | |||
@Controller | |||
public class EmpleadoController { | |||
@Autowired | |||
private EmpleadoServicio servicio; | |||
@GetMapping({"empleado/list"}) | |||
public String listado (Model model) { | |||
model.addAttribute("mensaje","Ramoncín esto es una prueba"); | |||
model.addAttribute("dominio","dom.getDominio()"); | |||
model.addAttribute("tld","dom.getTld()"); | |||
model.addAttribute("pagina","list"); | |||
model.addAttribute("listaEmpleados",servicio.findAll()); | |||
return "index"; | |||
} | |||
@GetMapping({"empleado/alta"}) | |||
public String alta (Model model) { | |||
model.addAttribute("mensaje","Ramoncín esto es una prueba"); | |||
model.addAttribute("dominio","dom.getDominio()"); | |||
model.addAttribute("tld","dom.getTld()"); | |||
model.addAttribute("empleadoForm", new Empleado()); | |||
model.addAttribute("pagina","alta"); | |||
return "index"; | |||
} | |||
@PostMapping("/empleado/new/submit") | |||
public String nuevoEmpleadoSubmit(@ModelAttribute("empleadoForm") Empleado nuevoEmpleado) { | |||
servicio.add(nuevoEmpleado); | |||
return "redirect:/empleado/list"; | |||
} | |||
} |
@ -0,0 +1,54 @@ | |||
package com.example.demo.models; | |||
import java.util.Objects; | |||
public class Director { | |||
private long id; | |||
private String name; | |||
public Director() {} | |||
public Director(long id, String name) { | |||
this.id = id; | |||
this.name = name; | |||
} | |||
public long getId() { | |||
return id; | |||
} | |||
public void setId(long id) { | |||
this.id = id; | |||
} | |||
public String getName() { | |||
return name; | |||
} | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
if (this == o) return true; | |||
if (o == null || getClass() != o.getClass()) return false; | |||
Director director = (Director) o; | |||
return id == director.id && Objects.equals(name, director.name); | |||
} | |||
@Override | |||
public int hashCode() { | |||
return Objects.hash(id, name); | |||
} | |||
@Override | |||
public String toString() { | |||
return "Director{" + | |||
"id=" + id + | |||
", name='" + name + '\'' + | |||
'}'; | |||
} | |||
} |
@ -0,0 +1,74 @@ | |||
package com.example.demo.models; | |||
import java.util.Objects; | |||
public class Empleado { | |||
private long id; | |||
private String nombre; | |||
private String email; | |||
private String telefono; | |||
public Empleado(){} | |||
@Override | |||
public boolean equals(Object o) { | |||
if (this == o) return true; | |||
if (o == null || getClass() != o.getClass()) return false; | |||
Empleado empleado = (Empleado) o; | |||
return getId() == empleado.getId() && getNombre().equals(empleado.getNombre()) && getEmail().equals(empleado.getEmail()) && getTelefono().equals(empleado.getTelefono()); | |||
} | |||
@Override | |||
public int hashCode() { | |||
return Objects.hash(getId(), getNombre(), getEmail(), getTelefono()); | |||
} | |||
public Empleado (long id, String nombre, String email, String telefono){ | |||
this.id = id; | |||
this.nombre = nombre; | |||
this.email = email; | |||
this.telefono = telefono; | |||
} | |||
@Override | |||
public String toString() { | |||
return "Empleado{" + | |||
"id=" + id + | |||
", nombre='" + nombre + '\'' + | |||
", email='" + email + '\'' + | |||
", telefono='" + telefono + '\'' + | |||
'}'; | |||
} | |||
public long getId() { | |||
return id; | |||
} | |||
public void setId(long id) { | |||
this.id = id; | |||
} | |||
public String getNombre() { | |||
return nombre; | |||
} | |||
public void setNombre(String nombre) { | |||
this.nombre = nombre; | |||
} | |||
public String getEmail() { | |||
return email; | |||
} | |||
public void setEmail(String email) { | |||
this.email = email; | |||
} | |||
public String getTelefono() { | |||
return telefono; | |||
} | |||
public void setTelefono(String telefono) { | |||
this.telefono = telefono; | |||
} | |||
} |
@ -0,0 +1,54 @@ | |||
package com.example.demo.models; | |||
import java.util.Objects; | |||
public class Genre { | |||
private long id; | |||
private String name; | |||
public Genre(){} | |||
public Genre(long id, String name) { | |||
this.id = id; | |||
this.name = name; | |||
} | |||
public long getId() { | |||
return id; | |||
} | |||
public void setId(long id) { | |||
this.id = id; | |||
} | |||
public String getName() { | |||
return name; | |||
} | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
if (this == o) return true; | |||
if (o == null || getClass() != o.getClass()) return false; | |||
Genre genre = (Genre) o; | |||
return id == genre.id && Objects.equals(name, genre.name); | |||
} | |||
@Override | |||
public int hashCode() { | |||
return Objects.hash(id, name); | |||
} | |||
@Override | |||
public String toString() { | |||
return "Genre{" + | |||
"id=" + id + | |||
", name='" + name + '\'' + | |||
'}'; | |||
} | |||
} |
@ -0,0 +1,36 @@ | |||
package com.example.demo.services; | |||
import com.example.demo.models.Empleado; | |||
import org.springframework.stereotype.Service; | |||
import javax.annotation.PostConstruct; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
@Service | |||
public class EmpleadoServicio { | |||
private List<Empleado> repositorio = new ArrayList<>(); | |||
public EmpleadoServicio() { | |||
} | |||
public Empleado add(Empleado e){ | |||
repositorio.add(e); | |||
return e; | |||
} | |||
public List<Empleado> findAll() { | |||
return repositorio; | |||
} | |||
@PostConstruct | |||
public void init() { | |||
repositorio.addAll( | |||
Arrays.asList(new Empleado(1,"Juan","[email protected]","1111111111"), | |||
new Empleado(2,"Perico","[email protected]","2222222222"), | |||
new Empleado(3,"Andrés","[email protected]","3333333333")) | |||
); | |||
} | |||
} |
@ -0,0 +1,10 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<meta charset="ISO-8859-1"> | |||
<title>Insert title here</title> | |||
</head> | |||
<body> | |||
hola 2 | |||
</body> | |||
</html> |
@ -0,0 +1,10 @@ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<meta charset="ISO-8859-1"> | |||
<title>Insert title here</title> | |||
</head> | |||
<body> | |||
hola | |||
</body> | |||
</html> |
@ -0,0 +1,4 @@ | |||
@charset "UTF-8"; | |||
body { | |||
background-color: white; | |||
} |
@ -0,0 +1,8 @@ | |||
@charset "UTF-8"; | |||
body { | |||
padding-bottom: 20px; | |||
} | |||
.navbar { | |||
margin-bottom: 20px; | |||
} |
@ -0,0 +1,42 @@ | |||
<div th:fragment="alta" class="flex-shrink-0"> | |||
<h1>Alta de empleados de la empresa</h1> | |||
<div class="container"> | |||
<div class="row"> | |||
<div class="col-md-offset-2 col-md-8"> | |||
<form method="post" action="#" th:action="${empleadoForm.id != 0} ? @{/empleado/edit/submit} : @{/empleado/new/submit}" | |||
th:object="${empleadoForm}"> | |||
<h1 th:text="${empleadoForm.id != 0} ? 'Editar empleado' : 'Nuevo empleado'">Nuevo empleado</h1> | |||
<div class="form-group" | |||
th:classappend="${#fields.hasErrors('id')} ? 'has-error'"> | |||
<label for="id">ID</label> <input type="text" | |||
class="form-control" id="id" placeholder="1" | |||
th:field="*{id}" | |||
th:attrappend="readonly=${empleadoForm.id != 0} ? 'readonly' : null"> | |||
<span th:if="${#fields.hasErrors('id')}" th:errors="*{id}" | |||
class="help-block" id="id-error">Errores</span> | |||
</div> | |||
<div class="form-group"> | |||
<label for="nombre">Nombre</label> <input type="text" | |||
class="form-control" id="nombre" placeholder="Nombre" | |||
th:field="*{nombre}" /> | |||
</div> | |||
<div class="form-group"> | |||
<label for="email">Email</label> | |||
<input type="email" class="form-control" id="email" | |||
placeholder="[email protected]" th:field="*{email}" /> | |||
</div> | |||
<div class="form-group"> | |||
<label for="telefono">Teléfono</label> <input type="tel" | |||
class="form-control" id="telefono" placeholder="954000000" th:field="*{telefono}" /> | |||
</div> | |||
<button type="submit" class="btn btn-default">Enviar</button> | |||
</form> | |||
</div> | |||
</div> | |||
</div> | |||
<!-- /.container --> | |||
</div> |
@ -0,0 +1,13 @@ | |||
<!DOCTYPE html> | |||
<html xmlns:th="http://www.thymeleaf.org"> | |||
<head> | |||
<title>Error page</title> | |||
<meta charset="utf-8" /> | |||
<link rel="stylesheet" href="css/main.css" th:href="@{/css/main.css}" /> | |||
</head> | |||
<body th:with="httpStatus=${T(org.springframework.http.HttpStatus).valueOf(#response.status)}"> | |||
<h1 th:text="|${httpStatus} - ${httpStatus.reasonPhrase}|"> Ha habido un error... </h1> | |||
<p th:utext="${errorMessage}">Error java.lang.NullPointerException</p> | |||
<a href="index.html" th:href="@{/index.html}">Volver al inicio</a> | |||
</body> | |||
</html> |
@ -0,0 +1,60 @@ | |||
<div th:fragment="main_footer" class="text-center text-lg-start bg-light text-muted"> | |||
<style> | |||
@media print { | |||
@page { | |||
margin: 0 0.8in; | |||
} | |||
} | |||
</style> | |||
<section> | |||
<div class="container text-center text-md-start mt-5"> | |||
<div class="row mt-3"> | |||
<div class="col-md-3 col-lg-4 col-xl-3 mx-auto mb-4"> | |||
<h6 class="text-uppercase fw-bold mb-4"> | |||
<p style = "margin-top: 10%"> <i class="fas fa-gem me-3"> </i>La Filmoteca</p> | |||
</h6> | |||
<p style="text-align: justify" > | |||
Acercamos de una manera intuitiva las mejores películas de la historia según nuestros expertos y las más | |||
prestigiosas publicaciones de este arte. | |||
</p> | |||
</div> | |||
<div class="col-md-4 col-lg-3 col-xl-3 mx-auto mb-md-0 mb-4"> | |||
<h6 class="text-uppercase fw-bold mb-4" style = "margin-top: 10%">Contacta con nosotros</h6> | |||
<p><i class="fas fa-home me-3"></i>Gata de Gorgos</p> | |||
<p><i class="fas fa-envelope me-3"></i>[email protected]</p> | |||
<p><i class="fas fa-phone me-3"></i> + 96 234 567 88</p> | |||
</div> | |||
</div> | |||
</div> | |||
</section> | |||
<div class="text-center p-4" style="background-color: rgba(0, 0, 0, 0.05); line-height: 90%;"> | |||
<p> 2023 © <b>La Filmoteca</b> </p> | |||
<p style = "font-size: smaller;"> Con la tecnologia de | |||
<a href="https://mdbootstrap.com/"style="text-decoration: none; color: black"> MDBootstrap.com </a> </p> | |||
<a type="button" class="btn btn-success mb-3" style="background-color: black;" id="crearpdf">Crear PDF</a> | |||
</div> | |||
<script> | |||
document.addEventListener("DOMContentLoaded", () => { | |||
let boton = document.getElementById("crearpdf"); | |||
let container = document.getElementById("contenedor"); | |||
boton.addEventListener("click", event => { | |||
event.preventDefault(); | |||
window.print(); | |||
}, false); | |||
container.addEventListener("click", event => { | |||
boton.style.display = "initial"; | |||
}, false); | |||
}, false); | |||
</script> | |||
</div> |
@ -0,0 +1,10 @@ | |||
<head th:fragment="main_head"> | |||
<meta charset="utf-8"> | |||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |||
<title th:text="${dominio}">Título de la página</title> | |||
<meta name="description" content=""> | |||
<link href="/webjars/bootstrap/css/bootstrap.min.css" rel="stylesheet"> | |||
<link href="/webjars/font-awesome/css/all.css" rel="stylesheet"> | |||
<link href="/css/estilo.css" rel="stylesheet"> | |||
</head> |
@ -0,0 +1,14 @@ | |||
<!doctype html> | |||
<html lang="es" xmlns:th="http://www.thymeleaf.org"> | |||
<head> | |||
<meta charset="utf-8"> | |||
<link rel="stylesheet" type="text/css" media="all" | |||
th:href="'/css/' + ${background} + '.css'"> | |||
<title th:text="${fechahora}">Hora</title> | |||
</head> | |||
<body> | |||
<h1>Hola thymeleaf hoy es ...</h1> | |||
<h1 th:text="${fechahora}"> </h1> | |||
</body> | |||
</html> |
@ -0,0 +1,27 @@ | |||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd"> | |||
<html lang="es" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> | |||
<head th:replace="head/head :: main_head"> | |||
<title th:text="${title}">Título de la página</title> | |||
</head> | |||
<body onload="mueveReloj()"> | |||
<header th:replace="header/nav :: main_menu"></header> | |||
<div th:switch="${pagina}"> | |||
<div th:case="list"> | |||
<main th:replace="empleado/list :: listado"></main> | |||
</div> | |||
<div th:case="alta"> | |||
<main th:replace="empleado/form :: alta"></main> | |||
</div> | |||
<div th:case="*"> | |||
<main th:replace="main/main_content :: index"></main> | |||
</div> | |||
</div> | |||
<footer th:replace="foot/footer :: main_footer"></footer> | |||
<script src="/webjars/jsquery/jquery.min.js"></script> | |||
<script src="/webjars/bootstrap/js/bootstrap.bundle.min.js"></script> | |||
<script src="/js/reloj.js"></script> | |||
</body> | |||
</html> |
@ -0,0 +1,27 @@ | |||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd"> | |||
<html lang="es" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> | |||
<head th:replace="head/head :: main_head"> | |||
<title th:text="${title}">Título de la página</title> | |||
</head> | |||
<body onload="mueveReloj()"> | |||
<header th:replace="header/nav/nav_header :: main_nav_header"></header> | |||
<div th:switch="${pagina}"> | |||
<div th:case="list"> | |||
<main th:replace="empleado/list :: listado"></main> | |||
</div> | |||
<div th:case="alta"> | |||
<main th:replace="empleado/form :: alta"></main> | |||
</div> | |||
<div th:case="*"> | |||
<main th:replace="main/main_content :: escribir_resenya"></main> | |||
</div> | |||
</div> | |||
<footer th:replace="foot/footer :: main_footer"></footer> | |||
<script src="/webjars/jsquery/jquery.min.js"></script> | |||
<script src="/webjars/bootstrap/js/bootstrap.bundle.min.js"></script> | |||
<script src="/js/reloj.js"></script> | |||
</body> | |||
</html> |
@ -0,0 +1,10 @@ | |||
<!DOCTYPE html> | |||
<html lang="en"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Title</title> | |||
</head> | |||
<body> | |||
</body> | |||
</html> |
@ -0,0 +1,27 @@ | |||
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd"> | |||
<html lang="es" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> | |||
<head th:replace="head/head :: main_head"> | |||
<title th:text="${title}">Título de la página</title> | |||
</head> | |||
<body onload="mueveReloj()"> | |||
<header th:replace="header/nav/nav_header :: main_nav_header"></header> | |||
<div th:switch="${pagina}"> | |||
<div th:case="list"> | |||
<main th:replace="empleado/list :: listado"></main> | |||
</div> | |||
<div th:case="alta"> | |||
<main th:replace="empleado/form :: alta"></main> | |||
</div> | |||
<div th:case="*"> | |||
<main th:replace="main/main_content :: generos"></main> | |||
</div> | |||
</div> | |||
<footer th:replace="foot/footer :: main_footer"></footer> | |||
<script src="/webjars/jsquery/jquery.min.js"></script> | |||
<script src="/webjars/bootstrap/js/bootstrap.bundle.min.js"></script> | |||
<script src="/js/reloj.js"></script> | |||
</body> | |||
</html> |
@ -0,0 +1,13 @@ | |||
package com.example.demo; | |||
import org.junit.jupiter.api.Test; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
@SpringBootTest | |||
class DemoApplicationTests { | |||
@Test | |||
void contextLoads() { | |||
} | |||
} |