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
f0517907
Commit
f0517907
authored
Nov 07, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Zapis danych z formularza - oddzielne parametry
parent
ebdc118a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletions
+22
-1
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+19
-0
SecurityConfig.java
...epSpring/src/main/java/sklep/security/SecurityConfig.java
+3
-1
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
f0517907
...
@@ -9,6 +9,7 @@ import org.springframework.stereotype.Controller;
...
@@ -9,6 +9,7 @@ import org.springframework.stereotype.Controller;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
...
@@ -90,6 +91,24 @@ public class ProductController {
...
@@ -90,6 +91,24 @@ public class ProductController {
return
"product_form"
;
return
"product_form"
;
}
}
@PostMapping
({
"/{id}/edit"
,
"/new"
})
// Ta metoda zapisuje dane przysłane z formularza obojętnie, czy to było edit, czy new
public
String
saveProduct
(
Integer
productId
,
String
productName
,
BigDecimal
price
,
BigDecimal
vat
,
String
description
,
Model
model
)
{
Product
product
=
new
Product
();
product
.
setProductId
(
productId
);
product
.
setProductName
(
productName
);
product
.
setPrice
(
price
);
product
.
setVat
(
vat
);
product
.
setDescription
(
description
);
System
.
out
.
println
(
"id przed zapisem: "
+
product
.
getProductId
());
productRepository
.
save
(
product
);
System
.
out
.
println
(
"id po zapisie: "
+
product
.
getProductId
());
model
.
addAttribute
(
"product"
,
product
);
return
"product_form"
;
}
@GetMapping
(
path
=
"/{id}/photo"
,
produces
=
"image/jpeg"
)
@GetMapping
(
path
=
"/{id}/photo"
,
produces
=
"image/jpeg"
)
@ResponseBody
@ResponseBody
public
byte
[]
getPhoto
(
@PathVariable
(
"id"
)
Integer
productId
)
{
public
byte
[]
getPhoto
(
@PathVariable
(
"id"
)
Integer
productId
)
{
...
...
PC30-SklepSpring/src/main/java/sklep/security/SecurityConfig.java
View file @
f0517907
...
@@ -10,7 +10,9 @@ public class SecurityConfig {
...
@@ -10,7 +10,9 @@ public class SecurityConfig {
@Bean
@Bean
SecurityFilterChain
configHttpSecurity
(
HttpSecurity
httpSecurity
)
throws
Exception
{
SecurityFilterChain
configHttpSecurity
(
HttpSecurity
httpSecurity
)
throws
Exception
{
httpSecurity
.
authorizeHttpRequests
(
authz
->
authz
.
anyRequest
().
permitAll
());
httpSecurity
.
authorizeHttpRequests
(
authz
->
authz
.
anyRequest
().
permitAll
())
.
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