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
b9822166
Commit
b9822166
authored
Feb 01, 2023
by
Oscar Gonzalez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
se agrega BeneficioController: listar, crear, actualizar
parent
d2fd2c1d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
curriculumsearch/src/main/java/com/roshka/controller/BeneficioController.java
+67
-0
No files found.
curriculumsearch/src/main/java/com/roshka/controller/BeneficioController.java
0 → 100644
View file @
b9822166
package
com
.
roshka
.
controller
;
import
com.roshka.modelo.Beneficio
;
import
com.roshka.repositorio.BeneficioRepository
;
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
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.Valid
;
@Controller
@RequestMapping
(
"/beneficios"
)
public
class
BeneficioController
{
BeneficioRepository
beneficioRepository
;
@Autowired
public
BeneficioController
(
BeneficioRepository
beneficioRepository
){
this
.
beneficioRepository
=
beneficioRepository
;
}
@GetMapping
(
path
=
{
"/agregar"
,
"/modificar/{id}"
})
public
String
addBeneficioView
(
Model
model
,
@PathVariable
(
required
=
false
)
Long
id
)
{
if
(
id
==
null
)
model
.
addAttribute
(
"beneficio"
,
new
Beneficio
());
else
model
.
addAttribute
(
"beneficio"
,
beneficioRepository
.
getById
(
id
));
return
"beneficio-form"
;
}
@RequestMapping
()
public
String
menuBeneficios
(
Model
model
,
@RequestParam
(
required
=
false
)
String
nombre
,
@RequestParam
(
defaultValue
=
"0"
)
Integer
nroPagina
)
{
final
Integer
CANTIDAD_POR_PAGINA
=
10
;
Pageable
page
=
PageRequest
.
of
(
nroPagina
,
CANTIDAD_POR_PAGINA
,
Sort
.
by
(
"id"
));
if
(
nombre
==
null
||
nombre
.
trim
().
isEmpty
())
{
Page
<
Beneficio
>
beneficioPag
=
beneficioRepository
.
findAllBeneficio
(
page
);
model
.
addAttribute
(
"beneficios"
,
beneficioPag
.
getContent
());
model
.
addAttribute
(
"pages"
,
beneficioPag
.
getTotalPages
());
}
else
{
Page
<
Beneficio
>
beneficioPag
=
beneficioRepository
.
findByTituloContainingIgnoreCase
(
nombre
.
trim
(),
page
);
model
.
addAttribute
(
"pages"
,
beneficioPag
.
getTotalPages
());
model
.
addAttribute
(
"beneficios"
,
beneficioPag
.
getContent
());
}
return
"beneficios"
;
}
@PostMapping
(
path
=
{
"/agregar"
,
"/modificar/{id}"
})
public
String
addBeneficio
(
@Valid
@ModelAttribute
Beneficio
beneficio
,
BindingResult
result
,
@PathVariable
(
required
=
false
)
Long
id
,
Model
model
)
{
if
(
result
.
hasErrors
()
||
(
id
==
null
&&
beneficioRepository
.
existsByTituloIgnoreCase
(
beneficio
.
getTitulo
()))){
model
.
addAttribute
(
"mismoNombre"
,
true
);
return
"beneficio-form"
;
}
if
(
id
!=
null
)
beneficio
.
setId
(
id
);
beneficioRepository
.
save
(
beneficio
);
return
"redirect:/beneficios"
;
}
}
\ 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