Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
Ecsite
Project
Project
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
shoei.kanno
Ecsite
Commits
97502a8e
Commit
97502a8e
authored
Oct 20, 2020
by
DESKTOP-FI5PFC1\tevir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
購入機能追加
parent
c4e0deca
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
3 deletions
+23
-3
EcsiteRestController.java
src/main/java/com/example/api/EcsiteRestController.java
+7
-1
EcsiteController.java
src/main/java/com/example/web/EcsiteController.java
+14
-0
index.html
src/main/resources/templates/index.html
+1
-1
list.html
src/main/resources/templates/list.html
+1
-1
No files found.
src/main/java/com/example/api/EcsiteRestController.java
View file @
97502a8e
...
...
@@ -10,6 +10,7 @@ import javax.servlet.http.HttpSession;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -52,19 +53,22 @@ public class EcsiteRestController {
}
@PostMapping
(
"inputCart"
)
public
void
inputCart
(
@RequestBody
ItemData
data
)
{
public
void
inputCart
(
@RequestBody
ItemData
data
,
Model
model
)
{
if
(
session
.
getAttribute
(
"cart"
)
==
null
){
LinkedHashMap
<
String
,
Items
>
cart
=
new
LinkedHashMap
<
String
,
Items
>();
String
id
=
data
.
getShoesId
().
toString
();
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
System
.
out
.
println
(
cart
);
session
.
setAttribute
(
"cart"
,
cart
);
session
.
setAttribute
(
"cartValue"
,
data
.
getQuantity
());
}
else
{
LinkedHashMap
<
String
,
Items
>
cart
=
new
LinkedHashMap
<
String
,
Items
>();
String
id
=
data
.
getShoesId
().
toString
();
cart
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
session
.
setAttribute
(
"cart"
,
cart
);
int
nowQuantity
=
(
int
)
session
.
getAttribute
(
"cartValue"
);
session
.
setAttribute
(
"cartValue"
,
nowQuantity
+
data
.
getQuantity
());
}
}
...
...
@@ -77,5 +81,6 @@ public class EcsiteRestController {
//User user = userDetails.getUser();
//Integer userId = user.getId();
salesLogService
.
update
(
1
,
cart
);
session
.
removeAttribute
(
"cart"
);
}
}
\ No newline at end of file
src/main/java/com/example/web/EcsiteController.java
View file @
97502a8e
...
...
@@ -75,6 +75,11 @@ HttpSession session;
public
String
top
(
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
)
{
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
if
(
session
.
getAttribute
(
"cartValue"
)
==
null
)
{
model
.
addAttribute
(
"cartValue"
,
0
);
}
else
{
model
.
addAttribute
(
"cartValue"
,
session
.
getAttribute
(
"cartValue"
));
}
//遷移先 設定済み
return
"index"
;
}
...
...
@@ -99,6 +104,12 @@ HttpSession session;
//user情報取得、格納
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
//カート個数取得、格納
if
(
session
.
getAttribute
(
"cartValue"
)
==
null
)
{
model
.
addAttribute
(
"cartValue"
,
0
);
}
else
{
model
.
addAttribute
(
"cartValue"
,
session
.
getAttribute
(
"cartValue"
));
}
//遷移先 未設定
return
"list"
;
}
...
...
@@ -128,6 +139,9 @@ HttpSession session;
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
items
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
if
(
items
==
null
)
{
return
"Cart"
;
}
items
.
forEach
((
key
,
value
)
->
{
cart
.
add
(
value
);
});
...
...
src/main/resources/templates/index.html
View file @
97502a8e
...
...
@@ -65,7 +65,7 @@
<ul
class=
"nav navbar-nav navbar-right cart-menu"
>
<li><a
href=
"#"
class=
"search-btn"
><i
class=
"fa fa-search"
aria-hidden=
"true"
></i></a></li>
<li><a
href=
"#"
><span>
Cart
</span>
<span
class=
"shoping-cart"
>
0
</span></a></li>
<li><a
href=
"#"
><span>
Cart
</span>
<span
th:text=
"${cartValue}"
class=
"shoping-cart"
>
0
</span></a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
...
...
src/main/resources/templates/list.html
View file @
97502a8e
...
...
@@ -91,7 +91,7 @@
<ul
class=
"nav navbar-nav navbar-right cart-menu"
>
<li><a
href=
"#"
class=
"search-btn"
><i
class=
"fa fa-search"
aria-hidden=
"true"
></i></a></li>
<li><a
href=
"#"
><span>
Cart
</span>
<span
class=
"shoping-cart"
>
0
</span></a></li>
<li><a
href=
"#"
><span>
Cart
</span>
<span
class=
"shoping-cart"
th:text=
"${cartValue}"
>
0
</span></a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
...
...
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