Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20230403
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
20230403
Commits
478ff824
Commit
478ff824
authored
Apr 26, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Zapisanie danych produktu z formularza - wersja z wieloma parametrami
parent
21a82542
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletions
+26
-1
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+24
-1
SecurityConfig.java
...epSpring/src/main/java/sklep/security/SecurityConfig.java
+2
-0
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
478ff824
package
sklep
.
controller
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.Optional
;
...
...
@@ -8,9 +9,11 @@ import org.springframework.stereotype.Controller;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
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.ResponseBody
;
import
jakarta.persistence.Column
;
import
sklep.model.Product
;
import
sklep.photo.PhotoUtil
;
import
sklep.repository.ProductRepository
;
...
...
@@ -65,5 +68,25 @@ public class ProductController {
return
"missing_product"
;
}
}
@PostMapping
({
"/new"
,
"/{id}/edit"
})
public
String
zapiszProdukt
(
Model
model
,
Integer
productId
,
String
description
,
BigDecimal
price
,
String
productName
,
BigDecimal
vat
)
{
System
.
out
.
println
(
"Parametry: "
+
productId
+
" "
+
productName
);
Product
product
=
new
Product
();
product
.
setProductId
(
productId
);
product
.
setProductName
(
productName
);
product
.
setDescription
(
description
);
product
.
setPrice
(
price
);
product
.
setVat
(
vat
);
System
.
out
.
println
(
"Obiekt przed zapisem: "
+
product
.
getProductId
()
+
" "
+
product
.
getProductName
());
productRepository
.
save
(
product
);
System
.
out
.
println
(
"Obiekt po zapisie: "
+
product
.
getProductId
()
+
" "
+
product
.
getProductName
());
model
.
addAttribute
(
"product"
,
product
);
return
"product_form"
;
}
}
PC30-SklepSpring/src/main/java/sklep/security/SecurityConfig.java
View file @
478ff824
...
...
@@ -11,6 +11,8 @@ public class SecurityConfig {
SecurityFilterChain
setHttpSecurity
(
HttpSecurity
httpSecurity
)
throws
Exception
{
httpSecurity
.
authorizeHttpRequests
()
.
anyRequest
().
permitAll
()
.
and
()
.
csrf
().
disable
()
;
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