From f4fb9b536a70d034c24ca5b1c83c4df5c336661c Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 1 Nov 2021 13:10:51 -0300 Subject: [PATCH] postulante controller recibir formato json --- curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java | 40 +++++++++++----------------------------- curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java | 24 +++++++++++++++++++++++- curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java | 34 ++++++++++++++++------------------ curriculumsearch/src/main/webapp/jsp/home.jsp | 85 ------------------------------------------------------------------------------------- curriculumsearch/src/main/webapp/jsp/index.jsp | 12 ++++++++++++ curriculumsearch/src/main/webapp/jsp/postulante-form.jsp | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 241 insertions(+), 133 deletions(-) delete mode 100644 curriculumsearch/src/main/webapp/jsp/home.jsp create mode 100644 curriculumsearch/src/main/webapp/jsp/index.jsp create mode 100644 curriculumsearch/src/main/webapp/jsp/postulante-form.jsp diff --git a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java index 6704d99..13fbf12 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java @@ -9,50 +9,32 @@ import com.roshka.modelo.Postulante; import com.roshka.repositorio.PostulanteRepository; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; @Controller public class PostulanteController { @Autowired PostulanteRepository post; + @RequestMapping("/") - public String index(){ - - return "home"; + public String index() { + return "index"; } - @PostMapping("/") - public String guardarPostulante( @RequestParam String nombre,@RequestParam String apellido, @RequestParam - String ci,@RequestParam String correo,@RequestParam String ciudad,@RequestParam String telefono, - @RequestParam String fechaNacimiento,@RequestParam String resumen,@RequestParam long nivelIngles, - @RequestParam String curriculum, @RequestParam String modalidad,@RequestParam String disponibilidad ){ + @RequestMapping("/postulante") + public String getFormPostulante(){ - try { - Date date1=new SimpleDateFormat("yyyy-mm-dd").parse(fechaNacimiento); - Postulante postulante= new Postulante(nombre, apellido, ci, correo, ciudad, - telefono,date1, resumen, - nivelIngles, curriculum, modalidad, disponibilidad); - post.save(postulante); - - } catch (Exception e) { - //TODO: handle exception - System.out.println(e); - } - - + return "postulante-form"; + } + @PostMapping(value = "/postulante",consumes = "application/json") + public String guardarPostulante(@RequestBody Postulante postulante){ - - - System.out.println( fechaNacimiento); - - return "dfg"; + return "redirect:/"; } } diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java b/curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java index 00a01c9..5818910 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java @@ -1,6 +1,8 @@ package com.roshka.modelo; -import java.sql.Date; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; @@ -46,12 +48,32 @@ public class Experiencia { public void setFechaDesde(Date fechaDesde) { this.fechaDesde = fechaDesde; } + public void setFechaDesde(String fechaDesde) { + if(fechaDesde==null || fechaDesde.isEmpty()) return; + + try { + this.fechaDesde = new SimpleDateFormat("yyyy-mm-dd").parse(fechaDesde); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } public Date getFechaHasta() { return fechaHasta; } public void setFechaHasta(Date fechaHasta) { this.fechaHasta = fechaHasta; } + public void setFechaHasta(String fechaHasta) { + if(fechaHasta==null || fechaHasta.isEmpty()) return; + + try { + this.fechaHasta = new SimpleDateFormat("yyyy-mm-dd").parse(fechaHasta); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } public String getReferencias() { return referencias; } diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java b/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java index 3614020..80a0358 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java @@ -1,6 +1,9 @@ package com.roshka.modelo; import javax.persistence.*; + +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -8,24 +11,6 @@ import java.util.List; @Entity @Table(name="postulante") public class Postulante { - - - public Postulante(String nombre, String apellido, String ci, String correo, String ciudad, String telefono, - Date fechaNacimiento, String resumen, long nivelIngles, String curriculum, String modalidad, - String disponibilidad) { - this.nombre = nombre; - this.apellido = apellido; - this.ci = ci; - this.correo = correo; - this.ciudad = ciudad; - this.telefono = telefono; - this.fechaNacimiento = fechaNacimiento; - this.resumen = resumen; - this.nivelIngles = nivelIngles; - this.curriculum = curriculum; - this.modalidad = modalidad; - this.disponibilidad = disponibilidad; - } @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="id") @@ -76,6 +61,7 @@ public class Postulante { @OneToMany(mappedBy = "postulante",cascade = CascadeType.ALL) private List estudios; + public long getId() { return id; } @@ -140,6 +126,18 @@ public class Postulante { this.fechaNacimiento = fechaNacimiento; } + public void setFechaNacimiento(String fechaNacimiento) { + if(fechaNacimiento==null || fechaNacimiento.isEmpty()) return; + try { + + this.fechaNacimiento = new SimpleDateFormat("yyyy-mm-dd").parse(fechaNacimiento); + } catch (ParseException e) { + // TODO Auto-generated catch block + System.err.println("Error al parsear"); + e.printStackTrace(); + } + } + public String getResumen() { return resumen; } diff --git a/curriculumsearch/src/main/webapp/jsp/home.jsp b/curriculumsearch/src/main/webapp/jsp/home.jsp deleted file mode 100644 index 83d4b1c..0000000 --- a/curriculumsearch/src/main/webapp/jsp/home.jsp +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - Hello, world! - - -

Hello, world!

- -
-
- - -
We'll never share your email with anyone else.
-
- -
- - -
-
- - -
- -
- - -
-
- - -
- -
- - -
- -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - -
- - - - - - - - - - \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/index.jsp b/curriculumsearch/src/main/webapp/jsp/index.jsp new file mode 100644 index 0000000..2f174d6 --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/index.jsp @@ -0,0 +1,12 @@ + + + + + + + Document + + + Form postulante + + \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp new file mode 100644 index 0000000..1ce4723 --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp @@ -0,0 +1,179 @@ + + + + + + + + + + + Hello, world! + + +

Hello, world!

+ +
+
+ + +
We'll never share your email with anyone else.
+
+ +
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + + + + + + + + + + +
+ +
+ +
+ + + + + + + + + + + \ No newline at end of file -- libgit2 0.26.0