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