From 1b08dcc3f52e9c510a7a28805fe4bf4117a008a3 Mon Sep 17 00:00:00 2001 From: willgonzz Date: Thu, 18 Nov 2021 15:50:33 -0300 Subject: [PATCH] Paginacion de las listas de tecnologias y cargos --- curriculumsearch/src/main/java/com/roshka/controller/CargoController.java | 17 +++++++++++++---- curriculumsearch/src/main/java/com/roshka/controller/TecnologiaController.java | 17 +++++++++++++---- curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java | 7 +++++++ curriculumsearch/src/main/java/com/roshka/repositorio/TecnologiaRepository.java | 7 +++++++ curriculumsearch/src/main/webapp/css/indexStyle.css | 2 +- curriculumsearch/src/main/webapp/jsp/cargos.jsp | 25 ++++++++++++++++++++++++- curriculumsearch/src/main/webapp/jsp/postulante-form.jsp | 2 +- curriculumsearch/src/main/webapp/jsp/tecnologias.jsp | 30 +++++++++++++++++++++++++++++- 8 files changed, 95 insertions(+), 12 deletions(-) diff --git a/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java b/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java index d1f6a84..262e9da 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java @@ -1,11 +1,17 @@ package com.roshka.controller; +import java.util.List; + import javax.validation.Valid; import com.roshka.modelo.Cargo; import com.roshka.repositorio.CargoRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -27,10 +33,13 @@ public class CargoController { } @RequestMapping("/cargos") - public String menuCargos(Model model, - @RequestParam(required = false) String nombre - ) { - if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("cargos", cargoRepo.findAll()); + public String menuCargos(Model model,@RequestParam(required = false) String nombre,@RequestParam(defaultValue = "0")Integer nroPagina) { + final Integer CANTIDAD_POR_PAGINA = 1; + Pageable page = PageRequest.of(nroPagina,CANTIDAD_POR_PAGINA,Sort.by("id")); + Page CargoPag=cargoRepo.findAllCargo(page); + List cargo = CargoPag.getContent(); + model.addAttribute("pages", CargoPag.getTotalPages()); + if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("cargos", cargo); else model.addAttribute("cargos", cargoRepo.findByNombreContainingIgnoreCase(nombre)); return "cargos"; } diff --git a/curriculumsearch/src/main/java/com/roshka/controller/TecnologiaController.java b/curriculumsearch/src/main/java/com/roshka/controller/TecnologiaController.java index b8649b2..fae8e1b 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/TecnologiaController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/TecnologiaController.java @@ -1,5 +1,7 @@ package com.roshka.controller; +import java.util.List; + import javax.validation.Valid; import com.roshka.modelo.Tecnologia; @@ -15,6 +17,10 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; @Controller public class TecnologiaController { @@ -38,10 +44,13 @@ public String addtecnologiaView(Model model,@PathVariable(required = false) Long } @RequestMapping("/tecnologias") - public String menuTecnologias(Model model, - @RequestParam(required = false) String nombre - ) { - if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("tecnologias", tecRepo.findAll()); + public String menuTecnologias(Model model,@RequestParam(required = false) String nombre,@RequestParam(defaultValue = "0")Integer nroPagina) { + final Integer CANTIDAD_POR_PAGINA = 5; + Pageable page = PageRequest.of(nroPagina,CANTIDAD_POR_PAGINA,Sort.by("id")); + Page tecnologiaPag=tecRepo.findAllTecnologia(page); + List tecnologia = tecnologiaPag.getContent(); + model.addAttribute("pages", tecnologiaPag.getTotalPages()); + if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("tecnologias", tecnologia); else model.addAttribute("tecnologias", tecRepo.findByNombreContainingIgnoreCase(nombre)); return "tecnologias"; } diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java index c78b922..dd7c024 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java @@ -4,9 +4,16 @@ import java.util.List; import com.roshka.modelo.Cargo; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface CargoRepository extends JpaRepository{ public List findByNombreContainingIgnoreCase(String nombre); + public boolean existsByNombreIgnoreCase(String nombre); + + @Query(value = "SELECT * FROM cargo",nativeQuery = true) + public Page findAllCargo(Pageable pageable ); } diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/TecnologiaRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/TecnologiaRepository.java index b1cbba7..8ed77e1 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/TecnologiaRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/TecnologiaRepository.java @@ -1,6 +1,9 @@ package com.roshka.repositorio; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; @@ -11,4 +14,8 @@ public interface TecnologiaRepository extends JpaRepository { public List findByNombreContainingIgnoreCase(String nombre); public boolean existsByNombreIgnoreCase(String nombre); + + + @Query(value = "SELECT * FROM tecnologia",nativeQuery = true) + public Page findAllTecnologia(Pageable pageable ); } diff --git a/curriculumsearch/src/main/webapp/css/indexStyle.css b/curriculumsearch/src/main/webapp/css/indexStyle.css index 6f1e132..3f7744c 100644 --- a/curriculumsearch/src/main/webapp/css/indexStyle.css +++ b/curriculumsearch/src/main/webapp/css/indexStyle.css @@ -3,6 +3,6 @@ body{ background-size:cover; background-repeat:no-repeat; height:100vh;width:100vw; - position: absolute; + -webkit-text-size-adjust: 100%; } \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/cargos.jsp b/curriculumsearch/src/main/webapp/jsp/cargos.jsp index a2f9b26..dad22a0 100644 --- a/curriculumsearch/src/main/webapp/jsp/cargos.jsp +++ b/curriculumsearch/src/main/webapp/jsp/cargos.jsp @@ -45,8 +45,31 @@ contentType="text/html;charset=UTF-8" language="java" %> + + - + diff --git a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp index a411b61..a0d8501 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp @@ -149,7 +149,7 @@ -
+
diff --git a/curriculumsearch/src/main/webapp/jsp/tecnologias.jsp b/curriculumsearch/src/main/webapp/jsp/tecnologias.jsp index c12e829..11a0930 100644 --- a/curriculumsearch/src/main/webapp/jsp/tecnologias.jsp +++ b/curriculumsearch/src/main/webapp/jsp/tecnologias.jsp @@ -39,5 +39,33 @@ - + + + + + + + + -- libgit2 0.26.0