Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_dzienna_15_09
Commits
d0008c2f
Commit
d0008c2f
authored
Oct 05, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Przekierowanie po poprawnym zapisie.
parent
33b8543b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+7
-3
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
d0008c2f
...
@@ -78,18 +78,22 @@ public class ProductController {
...
@@ -78,18 +78,22 @@ public class ProductController {
// Metoda jest wywoływana zawsze, a to programista ma sprawdzić czy walidacja się powiodła.
// Metoda jest wywoływana zawsze, a to programista ma sprawdzić czy walidacja się powiodła.
// W BindingResult znajdują się też informacje o błędach.
// W BindingResult znajdują się też informacje o błędach.
// Gdybyśmy mimo błędów spróbowali wywołać save, to wtedy Hibernate zablokuje taki zapis.
// Gdybyśmy mimo błędów spróbowali wywołać save, to wtedy Hibernate zablokuje taki zapis.
// W tej wersji po poprawnym zapisie przechodzimy na stronę ze szczegółami produktu.
if
(
bindingResult
.
hasErrors
())
{
if
(
bindingResult
.
hasErrors
())
{
model
.
addAttribute
(
"errors"
,
bindingResult
.
getAllErrors
());
// błędów już nie dodajemy oddzielne, bo będą wyświeltlone przez f:error
// model.addAttribute("errors", bindingResult.getAllErrors());
return
"product_form"
;
}
else
try
{
}
else
try
{
System
.
out
.
println
(
"Produkt przed zapisem: "
+
product
);
System
.
out
.
println
(
"Produkt przed zapisem: "
+
product
);
productRepository
.
save
(
product
);
productRepository
.
save
(
product
);
System
.
out
.
println
(
"Produkt po zapisie : "
+
product
);
System
.
out
.
println
(
"Produkt po zapisie : "
+
product
);
model
.
addAttribute
(
"saved"
,
true
);
return
"redirect:/products/"
+
product
.
getProductId
(
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Produkt bez zapisu : "
+
product
);
System
.
out
.
println
(
"Produkt bez zapisu : "
+
product
);
model
.
addAttribute
(
"errors"
,
ExceptionUtils
.
allMessages
(
e
));
model
.
addAttribute
(
"errors"
,
ExceptionUtils
.
allMessages
(
e
));
return
"product_form"
;
}
}
return
"product_form"
;
}
}
}
}
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