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
0
Merge Requests
0
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
Amparo Oliver
th-app-java
Commits
3448bb8a
Commit
3448bb8a
authored
Feb 02, 2023
by
Oscar Gonzalez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
se agrega BirthdayController: listar, crear, actualizar
parent
b9822166
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
curriculumsearch/src/main/java/com/roshka/controller/BirthdayController.java
+69
-0
No files found.
curriculumsearch/src/main/java/com/roshka/controller/BirthdayController.java
0 → 100644
View file @
3448bb8a
package
com
.
roshka
.
controller
;
import
com.roshka.modelo.Birthday
;
import
com.roshka.repositorio.BirthdayRepository
;
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.format.annotation.DateTimeFormat
;
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
;
import
java.util.Date
;
@Controller
@RequestMapping
(
"/cumples"
)
public
class
BirthdayController
{
BirthdayRepository
birthdayRepository
;
@Autowired
public
BirthdayController
(
BirthdayRepository
birthdayRepository
){
this
.
birthdayRepository
=
birthdayRepository
;
}
@GetMapping
(
path
=
{
"/agregar"
,
"/modificar/{id}"
})
public
String
addBirthdayView
(
Model
model
,
@PathVariable
(
required
=
false
)
Long
id
)
{
if
(
id
==
null
)
model
.
addAttribute
(
"cumple"
,
new
Birthday
());
else
model
.
addAttribute
(
"cumple"
,
birthdayRepository
.
getById
(
id
));
return
"birthday-form"
;
}
@RequestMapping
()
public
String
menuBirthdays
(
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
<
Birthday
>
birthdayPag
=
birthdayRepository
.
findAllBirthday
(
page
);
model
.
addAttribute
(
"cumples"
,
birthdayPag
.
getContent
());
model
.
addAttribute
(
"pages"
,
birthdayPag
.
getTotalPages
());
}
else
{
Page
<
Birthday
>
birthdayPag
=
birthdayRepository
.
findByNombreCompletoContainingIgnoreCase
(
nombre
.
trim
(),
page
);
model
.
addAttribute
(
"pages"
,
birthdayPag
.
getTotalPages
());
model
.
addAttribute
(
"cumples"
,
birthdayPag
.
getContent
());
}
return
"birthdays"
;
}
@PostMapping
(
path
=
{
"/agregar"
,
"/modificar/{id}"
})
public
String
addBirthday
(
@Valid
@ModelAttribute
Birthday
birthday
,
BindingResult
result
,
@PathVariable
(
required
=
false
)
Long
id
,
Model
model
)
{
if
(
result
.
hasErrors
()
||
(
id
==
null
&&
birthdayRepository
.
existsByNombreCompletoIgnoreCase
(
birthday
.
getNombreCompleto
()))){
model
.
addAttribute
(
"mismoNombre"
,
true
);
return
"birthday-form"
;
}
if
(
id
!=
null
)
birthday
.
setId
(
id
);
birthdayRepository
.
save
(
birthday
);
return
"redirect:/cumples"
;
}
}
\ 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