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
2bc89f53
Commit
2bc89f53
authored
Oct 20, 2020
by
keita.onoguchi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'カート機能' into 'master'
カート機能追加 See merge request
!40
parents
730430a0
8d42234c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
38 deletions
+22
-38
EcsiteRestController.java
src/main/java/com/example/api/EcsiteRestController.java
+9
-9
ItemData.java
src/main/java/com/example/domain/ItemData.java
+0
-3
EcsiteController.java
src/main/java/com/example/web/EcsiteController.java
+7
-8
cart.html
src/main/resources/templates/cart.html
+6
-18
No files found.
src/main/java/com/example/api/EcsiteRestController.java
View file @
2bc89f53
...
...
@@ -2,14 +2,12 @@ package com.example.api;
import
java.sql.Date
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -46,15 +44,18 @@ public class EcsiteRestController {
}
@PostMapping
(
"inputCart"
)
public
void
inputCart
(
@RequestBody
ItemData
data
,
HashMap
<
String
,
Items
>
cart
)
{
public
void
inputCart
(
@RequestBody
ItemData
data
)
{
if
(
session
.
getAttribute
(
"cart"
)
==
null
){
cart
.
put
((
data
.
getShoesId
()).
toString
(),
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
LinkedHashMap
<
String
,
Items
>
cart
=
new
LinkedHashMap
<
String
,
Items
>();
String
id
=
data
.
getShoesId
().
toString
();
cart
.
put
(
id
,
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
session
.
setAttribute
(
"cart"
,
cart
);
}
else
{
cart
=
(
HashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
cart
.
put
((
data
.
getShoesId
()).
toString
(),
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
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
);
}
}
}
\ No newline at end of file
src/main/java/com/example/domain/ItemData.java
View file @
2bc89f53
package
com
.
example
.
domain
;
import
org.springframework.stereotype.Component
;
import
lombok.Getter
;
import
lombok.Setter
;
@Component
@Setter
@Getter
public
class
ItemData
{
...
...
src/main/java/com/example/web/EcsiteController.java
View file @
2bc89f53
...
...
@@ -4,7 +4,7 @@ import java.io.ByteArrayOutputStream;
import
java.io.FileInputStream
;
import
java.sql.Date
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.
Linked
HashMap
;
import
java.util.List
;
import
javax.servlet.http.HttpSession
;
...
...
@@ -123,15 +123,14 @@ HttpSession session;
}
@GetMapping
(
"cart"
)
public
String
Cart
(
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
,
HashMap
<
String
,
Items
>
items
,
ArrayList
<
Items
>
cart
){
public
String
Cart
(
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
,
Linked
HashMap
<
String
,
Items
>
items
,
ArrayList
<
Items
>
cart
){
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
items
=
(
HashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
for
(
int
i
=
0
;
i
<
items
.
size
();
i
++){
String
key
=
String
.
valueOf
(
i
);
cart
.
add
(
items
.
get
(
key
));
}
System
.
out
.
println
((
cart
.
get
(
1
)).
getShoesName
());
items
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
items
.
forEach
((
key
,
value
)
->
{
cart
.
add
(
value
);
});
model
.
addAttribute
(
"cart"
,
cart
);
return
"Cart"
;
}
}
src/main/resources/templates/cart.html
View file @
2bc89f53
...
...
@@ -90,30 +90,18 @@
<tr
class=
"row"
id=
"theadTr"
>
<th
class=
"th col-xl-4"
id=
"imageTh"
>
Image
</th>
<th
class=
"th col-xl-4"
id=
"productNameTh"
>
Product Name
</th>
<th
class=
"th col-xl-4"
id=
"quantityTh"
>
Quantity
</th>
<th
class=
"th col-xl-4"
id=
"priceTh"
>
Price
</th>
</tr>
</thead>
<tbody>
<div
th:each=
"cart : ${cart}"
>
<tr
class=
"row tr"
>
<td
class=
"td col-xl-4"
><img
src=
"images/スニーカー2.jpg"
/></td>
<td
class=
"td col-xl-4"
><p
class=
"textP"
>
Convers All Star
</p></td>
<td
class=
"td col-xl-4"
><p
class=
"textP"
>
¥
10000
</p></td>
</tr>
<tr
class=
"row tr"
>
<td
class=
"td col-xl-4"
><img
src=
"images/スニーカー2.jpg"
/></td>
<td
class=
"td col-xl-4"
><p
class=
"textP"
>
Convers All Star
</p></td>
<td
class=
"td col-xl-4"
><p
class=
"textP"
>
¥
10000
</p></td>
</tr>
<tr
class=
"row tr"
>
<td
class=
"td col-xl-4"
><img
src=
"images/スニーカー2.jpg"
/></td>
<td
class=
"td col-xl-4"
><p
class=
"textP"
>
Convers All Star
</p></td>
<td
class=
"td col-xl-4"
><p
class=
"textP"
>
¥
10000
</p></td>
</tr>
<tr
class=
"row tr"
>
<td
class=
"td col-xl-4"
><img
src=
"images/スニーカー2.jpg"
/></td>
<td
class=
"td col-xl-4"
><p
class=
"textP"
>
Convers All Star
</p></td>
<td
class=
"td col-xl-4"
><p
class=
"textP"
>
¥
10000
</p></td>
<td
class=
"td col-xl-4"
><img
th:text=
"${cart.photo}"
src=
"images/スニーカー2.jpg"
/></td>
<td
class=
"td col-xl-4"
><p
th:text=
"${cart.shoesName}"
class=
"textP"
>
Convers All Star
</p></td>
<td
class=
"td col-xl-4"
><p
th:text=
"${cart.price}"
class=
"textP"
>
¥
10000
</p></td>
</tr>
</div>
</tbody>
</table>
<div
id=
"buy"
>
...
...
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