Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
th-app-java
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Oscar Enrique Gonzalez Escurra
th-app-java
Commits
f4fb9b53
Commit
f4fb9b53
authored
Nov 01, 2021
by
Joel Florentin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
postulante controller recibir formato json
parent
2d519b30
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
172 additions
and
62 deletions
+172
-62
curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java
+11
-29
curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java
+23
-1
curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java
+16
-18
curriculumsearch/src/main/webapp/jsp/index.jsp
+13
-0
curriculumsearch/src/main/webapp/jsp/postulante-form.jsp
+109
-14
No files found.
curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java
View file @
f4fb9b53
...
@@ -9,50 +9,32 @@ import com.roshka.modelo.Postulante;
...
@@ -9,50 +9,32 @@ import com.roshka.modelo.Postulante;
import
com.roshka.repositorio.PostulanteRepository
;
import
com.roshka.repositorio.PostulanteRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.PostMapping
;
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.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
@Controller
@Controller
public
class
PostulanteController
{
public
class
PostulanteController
{
@Autowired
@Autowired
PostulanteRepository
post
;
PostulanteRepository
post
;
@RequestMapping
(
"/"
)
@RequestMapping
(
"/"
)
public
String
index
(){
public
String
index
()
{
return
"index"
;
return
"home"
;
}
}
@PostMapping
(
"/"
)
@RequestMapping
(
"/postulante"
)
public
String
guardarPostulante
(
@RequestParam
String
nombre
,
@RequestParam
String
apellido
,
@RequestParam
public
String
getFormPostulante
(){
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
){
try
{
return
"postulante-form"
;
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
);
}
@PostMapping
(
value
=
"/postulante"
,
consumes
=
"application/json"
)
public
String
guardarPostulante
(
@RequestBody
Postulante
postulante
){
return
"redirect:/"
;
System
.
out
.
println
(
fechaNacimiento
);
return
"dfg"
;
}
}
}
}
curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java
View file @
f4fb9b53
package
com
.
roshka
.
modelo
;
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.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
...
@@ -46,12 +48,32 @@ public class Experiencia {
...
@@ -46,12 +48,32 @@ public class Experiencia {
public
void
setFechaDesde
(
Date
fechaDesde
)
{
public
void
setFechaDesde
(
Date
fechaDesde
)
{
this
.
fechaDesde
=
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
()
{
public
Date
getFechaHasta
()
{
return
fechaHasta
;
return
fechaHasta
;
}
}
public
void
setFechaHasta
(
Date
fechaHasta
)
{
public
void
setFechaHasta
(
Date
fechaHasta
)
{
this
.
fechaHasta
=
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
()
{
public
String
getReferencias
()
{
return
referencias
;
return
referencias
;
}
}
...
...
curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java
View file @
f4fb9b53
package
com
.
roshka
.
modelo
;
package
com
.
roshka
.
modelo
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -8,24 +11,6 @@ import java.util.List;
...
@@ -8,24 +11,6 @@ import java.util.List;
@Entity
@Entity
@Table
(
name
=
"postulante"
)
@Table
(
name
=
"postulante"
)
public
class
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
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
@Column
(
name
=
"id"
)
@Column
(
name
=
"id"
)
...
@@ -76,6 +61,7 @@ public class Postulante {
...
@@ -76,6 +61,7 @@ public class Postulante {
@OneToMany
(
mappedBy
=
"postulante"
,
cascade
=
CascadeType
.
ALL
)
@OneToMany
(
mappedBy
=
"postulante"
,
cascade
=
CascadeType
.
ALL
)
private
List
<
Estudio
>
estudios
;
private
List
<
Estudio
>
estudios
;
public
long
getId
()
{
public
long
getId
()
{
return
id
;
return
id
;
}
}
...
@@ -140,6 +126,18 @@ public class Postulante {
...
@@ -140,6 +126,18 @@ public class Postulante {
this
.
fechaNacimiento
=
fechaNacimiento
;
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
()
{
public
String
getResumen
()
{
return
resumen
;
return
resumen
;
}
}
...
...
curriculumsearch/src/main/webapp/jsp/index.jsp
0 → 100644
View file @
f4fb9b53
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Document
</title>
</head>
<body>
<a
href=
"postulante"
>
Form postulante
</a>
</body>
</html>
\ No newline at end of file
curriculumsearch/src/main/webapp/jsp/
home
.jsp
→
curriculumsearch/src/main/webapp/jsp/
postulante-form
.jsp
View file @
f4fb9b53
...
@@ -10,64 +10,79 @@
...
@@ -10,64 +10,79 @@
<title>
Hello, world!
</title>
<title>
Hello, world!
</title>
</head>
</head>
<body>
<body
class=
"container"
>
<h1>
Hello, world!
</h1>
<h1>
Hello, world!
</h1>
<form
name=
"postulante"
method=
"post"
>
<form
name=
"postulante"
method=
"post"
>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"correo"
class=
"form-label"
>
Email address
</label>
<label
for=
"correo"
class=
"form-label"
>
Email address
</label>
<input
type=
"email"
name=
"correo"
class=
"form-control "
id=
"correo"
aria-describedby=
"emailHelp"
>
<input
type=
"email"
name=
"correo"
class=
"form-control "
id=
"correo"
>
<div
id=
"emailHelp"
class=
"form-text"
>
We'll never share your email with anyone else.
</div>
<div
id=
"emailHelp"
class=
"form-text"
>
We'll never share your email with anyone else.
</div>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"nombre"
class=
"form-label"
>
Nombre
</label>
<label
for=
"nombre"
class=
"form-label"
>
Nombre
</label>
<input
type=
"text"
name=
"nombre"
class=
"form-control "
id=
"nombre"
aria-describedby=
"emailHelp"
>
<input
type=
"text"
name=
"nombre"
class=
"form-control "
id=
"nombre"
>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"apellido"
class=
"form-label"
>
Apellido
</label>
<label
for=
"apellido"
class=
"form-label"
>
Apellido
</label>
<input
type=
"text"
name=
"apellido"
class=
"form-control "
id=
"apellido"
aria-describedby=
"emailHelp"
>
<input
type=
"text"
name=
"apellido"
class=
"form-control "
id=
"apellido"
>
</div>
</div>
<div
class=
"mb-3 col-3"
>
<div
class=
"mb-3 col-3"
>
<label
for=
"ci"
class=
"form-label"
>
Cedula de identidad
</label>
<label
for=
"ci"
class=
"form-label"
>
Cedula de identidad
</label>
<input
type=
"number"
name=
"ci"
class=
"form-control "
id=
"ci"
aria-describedby=
"emailHelp"
>
<input
type=
"number"
name=
"ci"
class=
"form-control "
id=
"ci"
>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"ciudad"
class=
"form-label"
>
Ciudad
</label>
<label
for=
"ciudad"
class=
"form-label"
>
Ciudad
</label>
<input
type=
"text"
name=
"ciudad"
class=
"form-control "
id=
"ciudad"
aria-describedby=
"emailHelp"
>
<input
type=
"text"
name=
"ciudad"
class=
"form-control "
id=
"ciudad"
>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"telefono"
class=
"form-label"
>
Telefono
</label>
<label
for=
"telefono"
class=
"form-label"
>
Telefono
</label>
<input
type=
"number"
name=
"telefono"
class=
"form-control "
id=
"telefono"
aria-describedby=
"emailHelp"
>
<input
type=
"number"
name=
"telefono"
class=
"form-control "
id=
"telefono"
>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"fechaNacimiento"
class=
"form-label"
>
Fecha de nacimiento
</label>
<label
for=
"fechaNacimiento"
class=
"form-label"
>
Fecha de nacimiento
</label>
<input
type=
"date"
name=
"fechaNacimiento"
class=
"form-control "
id=
"fechaNacimiento"
aria-describedby=
"emailHelp"
>
<input
type=
"date"
name=
"fechaNacimiento"
class=
"form-control "
id=
"fechaNacimiento"
>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"resumen"
class=
"form-label"
>
Resumen
</label>
<label
for=
"resumen"
class=
"form-label"
>
Resumen
</label>
<textarea
class=
"form-control "
name=
"resumen"
id=
"resumen"
aria-describedby=
"emailHelp"
>
</textarea>
<textarea
class=
"form-control "
name=
"resumen"
id=
"resumen"
>
</textarea>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"nivelIngles"
class=
"form-label"
>
Nivel de ingles
</label>
<label
for=
"nivelIngles"
class=
"form-label"
>
Nivel de ingles
</label>
<input
type=
"
text"
class=
"form-control"
name=
"nivelIngles"
id=
"nivelIngles"
aria-describedby=
"emailHelp"
>
<input
type=
"
number"
class=
"form-control"
name=
"nivelIngles"
id=
"nivelIngles"
>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"curriculum"
class=
"form-label"
>
Curriculum
</label>
<label
for=
"curriculum"
class=
"form-label"
>
Curriculum
</label>
<input
type=
"text"
name=
"curriculum"
class=
"form-control "
id=
"curriculum"
aria-describedby=
"emailHelp"
>
<input
type=
"text"
name=
"curriculum"
class=
"form-control "
id=
"curriculum"
>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"disponibilidad"
class=
"form-label"
>
Disponibilidad
</label>
<label
for=
"disponibilidad"
class=
"form-label"
>
Disponibilidad
</label>
<input
type=
"text"
class=
"form-control "
name=
"disponibilidad"
id=
"disponibilidad"
aria-describedby=
"emailHelp"
>
<input
type=
"text"
class=
"form-control "
name=
"disponibilidad"
id=
"disponibilidad"
>
</div>
</div>
<div
class=
"mb-3 col-5"
>
<div
class=
"mb-3 col-5"
>
<label
for=
"modalidad"
class=
"form-label"
>
Modalidad
</label>
<label
for=
"modalidad"
class=
"form-label"
>
Modalidad
</label>
<input
type=
"text"
class=
"form-control "
name=
"modalidad"
id=
"modalidad"
aria-describedby=
"emailHelp"
>
<input
type=
"text"
class=
"form-control "
name=
"modalidad"
id=
"modalidad"
>
</div>
</div>
<fieldset>
<div
class=
"mb-3 col-5"
>
<label
for=
"institucion"
class=
"form-label"
>
Institucion
</label>
<input
type=
"text"
class=
"form-control "
name=
"experiencia-0-institucion"
id=
"institucion"
>
<label
for=
"fechaDesde"
class=
"form-label"
>
FechaDesde
</label>
<input
type=
"date"
class=
"form-control "
name=
"experiencia-0-fechaDesde"
id=
"fechaDesde"
>
<label
for=
"fechaHasta"
class=
"form-label"
>
Fecha Hasta
</label>
<input
type=
"date"
class=
"form-control "
name=
"experiencia-0-fechaHasta"
id=
"fechaHasta"
>
<label
for=
"cargo"
class=
"form-label"
>
Cargo
</label>
<input
type=
"cargo"
class=
"form-control "
name=
"experiencia-0-cargo"
id=
"cargo"
>
<label
for=
"refNombre"
class=
"form-label"
>
Referencia Nombre
</label>
<input
type=
"text"
class=
"form-control "
name=
"experiencia-0-referencias"
id=
"refNombre"
>
</div>
</fieldset>
<button
type=
"submit"
class=
"btn btn-primary"
>
Submit
</button>
<button
type=
"submit"
class=
"btn btn-primary"
>
Submit
</button>
</form>
</form>
...
@@ -81,5 +96,84 @@
...
@@ -81,5 +96,84 @@
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
-->
-->
<script>
let
cont_experiencia
=
0
;
let
cont_estudios
=
0
;
let
cont_tecnologia
=
0
;
function
serializeJSON
(
form
)
{
// Create a new FormData object
const
formData
=
new
FormData
(
form
);
// Create an object to hold the name/value pairs
const
pairs
=
{};
const
experiencias
=
[{}];
const
estudios
=
[{}];
const
tecnologias
=
[{}];
// Add each name/value pair to the object
for
(
const
[
name
,
value
]
of
formData
)
{
//los atributos no primitivos tiene una nomenclatura distinta en sus names
//ej.: experiencia-4-institucion == experencias[4].institucion
let
codificacion
=
name
.
split
(
"-"
)
if
(
codificacion
.
length
==
1
){
pairs
[
name
]
=
value
}
else
{
switch
(
codificacion
[
0
])
{
case
"experiencia"
:
if
(
experiencias
[
codificacion
[
1
]]
==
null
)
experiencias
[
codificacion
[
1
]]
=
{};
experiencias
[
codificacion
[
1
]][
codificacion
[
2
]]
=
value
break
;
case
"estudio"
:
if
(
estudios
[
codificacion
[
1
]]
==
null
)
estudios
[
codificacion
[
1
]]
=
{};
estudios
[
codificacion
[
1
]][
codificacion
[
2
]]
=
value
break
;
case
"tecnologia"
:
if
(
tecnologias
[
codificacion
[
1
]]
==
null
)
tecnologias
[
codificacion
[
1
]]
=
{};
tecnologias
[
codificacion
[
1
]][
codificacion
[
2
]]
=
value
break
;
default
:
break
;
}
}
}
pairs
[
"experiencias"
]
=
experiencias
pairs
[
"estudios"
]
=
estudios
pairs
[
"tecnologias"
]
=
tecnologias
// Return the JSON string
return
JSON
.
stringify
(
pairs
,
null
,
2
);
}
async
function
postData
(
url
=
''
,
data
=
{})
{
// Default options are marked with *
const
response
=
await
fetch
(
url
,
{
method
:
'POST'
,
// *GET, POST, PUT, DELETE, etc.
mode
:
'cors'
,
// no-cors, *cors, same-origin
cache
:
'no-cache'
,
// *default, no-cache, reload, force-cache, only-if-cached
credentials
:
'same-origin'
,
// include, *same-origin, omit
headers
:
{
'Content-Type'
:
'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect
:
'follow'
,
// manual, *follow, error
referrerPolicy
:
'no-referrer'
,
// no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body
:
data
// body data type must match "Content-Type" header
});
return
response
;
// parses JSON response into native JavaScript objects
}
form
=
document
.
querySelector
(
"form"
);
form
.
addEventListener
(
"submit"
,(
evt
)
=>
{
postData
(
'postulante'
,
serializeJSON
(
form
))
.
then
(
response
=>
{
console
.
log
(
response
);
// JSON data parsed by `data.json()` call
location
.
replace
(
response
.
url
);
});
evt
.
preventDefault
();
}
);
</script>
</body>
</body>
</html>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment