Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
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
javab_20230928
Commits
23a4b8ba
Commit
23a4b8ba
authored
Nov 07, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Przekierowanie na listę towarów po zapisaniu i inne drobne zmiany
parent
f1f582a8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
3 deletions
+6
-3
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+4
-2
SecurityConfig.java
...epSpring/src/main/java/sklep/security/SecurityConfig.java
+2
-1
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
23a4b8ba
...
@@ -5,6 +5,7 @@ import java.util.List;
...
@@ -5,6 +5,7 @@ import java.util.List;
import
java.util.Optional
;
import
java.util.Optional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.BindingResult
;
...
@@ -27,7 +28,7 @@ public class ProductController {
...
@@ -27,7 +28,7 @@ public class ProductController {
@GetMapping
@GetMapping
public
String
readAll
(
Model
model
)
{
public
String
readAll
(
Model
model
)
{
List
<
Product
>
products
=
productRepository
.
findAll
();
List
<
Product
>
products
=
productRepository
.
findAll
(
Sort
.
by
(
"productId"
)
);
model
.
addAttribute
(
"products"
,
products
);
model
.
addAttribute
(
"products"
,
products
);
return
"products"
;
return
"products"
;
}
}
...
@@ -110,14 +111,15 @@ public class ProductController {
...
@@ -110,14 +111,15 @@ public class ProductController {
System
.
out
.
println
(
"Są błedy: "
+
bindingResult
.
getAllErrors
());
System
.
out
.
println
(
"Są błedy: "
+
bindingResult
.
getAllErrors
());
// normalnie wyświetlilibyśmy coś na stronie...
// normalnie wyświetlilibyśmy coś na stronie...
// ale robi to za nas tag f:form i f:errors
// ale robi to za nas tag f:form i f:errors
return
"product_form"
;
}
else
{
}
else
{
// Gdy podczas próby zapisu (operacja save) obiekt nie spełnia warunków walidacji, to jest wyrzucany wyjątek.
// Gdy podczas próby zapisu (operacja save) obiekt nie spełnia warunków walidacji, to jest wyrzucany wyjątek.
System
.
out
.
println
(
"id przed zapisem: "
+
product
.
getProductId
());
System
.
out
.
println
(
"id przed zapisem: "
+
product
.
getProductId
());
productRepository
.
save
(
product
);
productRepository
.
save
(
product
);
System
.
out
.
println
(
"id po zapisie: "
+
product
.
getProductId
());
System
.
out
.
println
(
"id po zapisie: "
+
product
.
getProductId
());
return
"redirect:/products"
;
}
}
return
"product_form"
;
}
}
@GetMapping
(
path
=
"/{id}/photo"
,
produces
=
"image/jpeg"
)
@GetMapping
(
path
=
"/{id}/photo"
,
produces
=
"image/jpeg"
)
...
...
PC30-SklepSpring/src/main/java/sklep/security/SecurityConfig.java
View file @
23a4b8ba
...
@@ -12,7 +12,8 @@ public class SecurityConfig {
...
@@ -12,7 +12,8 @@ public class SecurityConfig {
SecurityFilterChain
configHttpSecurity
(
HttpSecurity
httpSecurity
)
throws
Exception
{
SecurityFilterChain
configHttpSecurity
(
HttpSecurity
httpSecurity
)
throws
Exception
{
httpSecurity
httpSecurity
.
authorizeHttpRequests
(
authz
->
authz
.
anyRequest
().
permitAll
())
.
authorizeHttpRequests
(
authz
->
authz
.
anyRequest
().
permitAll
())
.
csrf
(
authz
->
authz
.
disable
());
// .csrf(authz -> authz.disable())
;
return
httpSecurity
.
build
();
return
httpSecurity
.
build
();
}
}
...
...
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