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
b34bf391
Commit
b34bf391
authored
Nov 07, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
@SessionAttribute
parent
a8285ec0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
3 deletions
+2
-3
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+2
-3
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
b34bf391
...
...
@@ -14,6 +14,7 @@ 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
org.springframework.web.bind.annotation.SessionAttribute
;
import
jakarta.servlet.http.HttpSession
;
import
jakarta.validation.Valid
;
...
...
@@ -125,11 +126,9 @@ public class ProductController {
@GetMapping
(
"/{id}/add-to-basket"
)
public
String
addToBasket
(
@PathVariable
(
"id"
)
Integer
productId
,
HttpSession
sesja
)
{
@SessionAttribute
Basket
basket
)
{
Optional
<
Product
>
product
=
productRepository
.
findById
(
productId
);
if
(
product
.
isPresent
())
{
// w tej wersji zakładamy, że listener przygotował pusty koszyk
Basket
basket
=
(
Basket
)
sesja
.
getAttribute
(
"basket"
);
basket
.
addProduct
(
product
.
get
());
}
else
{
System
.
err
.
println
(
"Nieznany produkt dodawany do koszyka: "
+
productId
);
...
...
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