質問編集履歴
4
意図的な内容抹消の取り消し
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,1 +1,110 @@
|
|
1
|
+
### 前提・実現したいこと
|
1
|
-
|
2
|
+
springフレームワークを使ってアクセサリーショップのECサイトを作成しております。
|
3
|
+
htmlの表示が思うように表示されず困っています。
|
4
|
+
そのためコントローラやリポジトリが正しいのかも分かりません。
|
5
|
+
プログラミング初心者です。
|
6
|
+
ご教授ください。
|
7
|
+
メインページの商品の一覧として、
|
8
|
+
・過去に注文履歴がない場合→新着順に商品が表示される
|
9
|
+
・過去に注文履歴がない(未ログインor会員登録はあるが注文履歴がない)場合→売筋順に商品が表示される
|
10
|
+
トップページを作りたいのですが商品が全く表示されません。
|
11
|
+
原因と対処法を教えていただけますと、幸いです。
|
12
|
+
### 発生している問題・エラーメッセージ
|
13
|
+
実行エラーは出ないのですが、
|
14
|
+
ネットワークで開いてみると
|
15
|
+
表またはビューが存在しません。
|
16
|
+
と表示されます。
|
17
|
+
### オーダーアイテムリポジトリ
|
18
|
+
```
|
19
|
+
public interface OrderItemRepository extends JpaRepository<OrderItem, Integer> {
|
20
|
+
//注文票(オーダーアイテム)の商品を集計し、それをカウントする
|
21
|
+
@Query(value="select OrderItem(item) from OrderItem o group by o.item order by count(o.item) desc", nativeQuery=true)
|
22
|
+
public List<OrderItem> findItem();
|
23
|
+
```
|
24
|
+
### コントローラ
|
25
|
+
```
|
26
|
+
@RequestMapping(path = "/")
|
27
|
+
public String menu( Model model, Pageable pageable) {
|
28
|
+
//売れ筋順で商品検索
|
29
|
+
List<OrderItem>orderItemList = orderItemRepository.findItem();
|
30
|
+
List<Item> items = new ArrayList<Item>();
|
31
|
+
//for文でカウント
|
32
|
+
for(int i=0; i< orderItemList.size(); i++) {
|
33
|
+
if (orderItemList.get(i).getItem().getDeleteFlag()==0)
|
34
|
+
items.add(orderItemList.get(i).getItem());
|
35
|
+
}
|
36
|
+
//ページ、ページ遷移処理
|
37
|
+
Page<Item> pages= Convert.listConvertToPage(items,pageable);
|
38
|
+
//ビューに商品情報を渡す処理
|
39
|
+
model.addAttribute("items",pages.getContent());
|
40
|
+
Page<Item>itemList = null;
|
41
|
+
//商品が空の場合は新着順検索
|
42
|
+
if(items.isEmpty()) {
|
43
|
+
itemList= itemRepository.findByDeleteFlagOrderByInsertDateDesc(Constant.NOT_DELETED,pageable);
|
44
|
+
// エンティティ内の検索結果をJavaBeansにコピー
|
45
|
+
List<ItemBean> itemBeanList =
|
46
|
+
BeanCopy.copyEntityToItemBean(itemList.getContent());
|
47
|
+
// 商品情報をViewへ渡す
|
48
|
+
model.addAttribute("items", itemBeanList);
|
49
|
+
model.addAttribute("flg", 1);
|
50
|
+
}
|
51
|
+
return "index";
|
52
|
+
```
|
53
|
+
###コンバーター
|
54
|
+
```
|
55
|
+
public class Convert {
|
56
|
+
public static <T> Page<T> listConvertToPage(List<T> list, Pageable pageable) {
|
57
|
+
int start = (int)pageable.getOffset();
|
58
|
+
int end= (start + pageable.getPageSize()) > list.size() ? list.size() : ( start + pageable.getPageSize());
|
59
|
+
return new PageImpl<T>(list.subList(start, end), pageable, list.size());
|
60
|
+
}}
|
61
|
+
```
|
62
|
+
### HTML
|
63
|
+
```
|
64
|
+
<!DOCTYPE html>
|
65
|
+
<html xmlns:th="http://www.thymeleaf.org"
|
66
|
+
th:replace="~{common/layout_5block :: layout(~{::body/content()})}">
|
67
|
+
<head>
|
68
|
+
<title>トップ </title>
|
69
|
+
<meta charset="UTF-8" />
|
70
|
+
</head>
|
71
|
+
<body class="user index">
|
72
|
+
<!-- 売れ筋商品の場合表示 -->
|
73
|
+
<div th:if="${flg==1}">
|
74
|
+
<h2 class="title">売れ筋商品</h2>
|
75
|
+
</div>
|
76
|
+
<!-- 新着商品の場合表示 -->
|
77
|
+
<div th:if="${flg!=1}">
|
78
|
+
<h2 class="title">新着商品</h2>
|
79
|
+
</div>
|
80
|
+
|
81
|
+
<!-- 商品情報がない場合は無い旨を表示 -->
|
82
|
+
<div th:if="${#lists. isEmpty(items)}">
|
83
|
+
<p th:text="#{itemList.none}" />
|
84
|
+
</div>
|
85
|
+
|
86
|
+
<!-- 商品情報がある場合 -->
|
87
|
+
<!-- 情報の商品画像を表示、または無画像を表示 -->
|
88
|
+
|
89
|
+
<div th:if="!${#lists.isEmpty(items)}">
|
90
|
+
|
91
|
+
<div class="item" th:each="item: ${items}">
|
92
|
+
<span th:if="${item.image != null}">
|
93
|
+
|
94
|
+
<!-- 画像をクリックすることで商品画面に遷移 -->
|
95
|
+
<a th:href="@{/item/detail//{id}(id=${item.id})}">
|
96
|
+
<img th:src="@{/img/{image}(image=${item.image})}"></img></a>
|
97
|
+
</span>
|
98
|
+
|
99
|
+
<span th:if="${item.image == null}">
|
100
|
+
<img th:src="@{/img/common/no_image.jpg}"></img>
|
101
|
+
</span>
|
102
|
+
</div>
|
103
|
+
</div>
|
104
|
+
</body>
|
105
|
+
</html>
|
106
|
+
```
|
107
|
+
### 試したこと
|
108
|
+
ここに問題に対して試したことを記載してください。
|
109
|
+
### 補足情報(FW/ツールのバージョンなど)
|
110
|
+
ここにより詳細な情報を記載してください。
|
3
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,137 +1,1 @@
|
|
1
|
-
### 前提・実現したいこと
|
2
|
-
|
1
|
+
解決しました解決しました解決しました解決しました解決しました解決しました解決しました
|
3
|
-
htmlの表示が思うように表示されず困っています。
|
4
|
-
そのためコントローラやリポジトリが正しいのかも分かりません。
|
5
|
-
プログラミング初心者です。
|
6
|
-
ご教授ください。
|
7
|
-
|
8
|
-
メインページの商品の一覧として、
|
9
|
-
|
10
|
-
・過去に注文履歴がない場合→新着順に商品が表示される
|
11
|
-
・過去に注文履歴がない(未ログインor会員登録はあるが注文履歴がない)場合→売筋順に商品が表示される
|
12
|
-
|
13
|
-
トップページを作りたいのですが商品が全く表示されません。
|
14
|
-
原因と対処法を教えていただけますと、幸いです。
|
15
|
-
|
16
|
-
### 発生している問題・エラーメッセージ
|
17
|
-
実行エラーは出ないのですが、
|
18
|
-
ネットワークで開いてみると
|
19
|
-
表またはビューが存在しません。
|
20
|
-
と表示されます。
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
### オーダーアイテムリポジトリ
|
25
|
-
```
|
26
|
-
public interface OrderItemRepository extends JpaRepository<OrderItem, Integer> {
|
27
|
-
//注文票(オーダーアイテム)の商品を集計し、それをカウントする
|
28
|
-
@Query(value="select OrderItem(item) from OrderItem o group by o.item order by count(o.item) desc", nativeQuery=true)
|
29
|
-
public List<OrderItem> findItem();
|
30
|
-
|
31
|
-
```
|
32
|
-
|
33
|
-
### コントローラ
|
34
|
-
```
|
35
|
-
@RequestMapping(path = "/")
|
36
|
-
public String menu( Model model, Pageable pageable) {
|
37
|
-
//売れ筋順で商品検索
|
38
|
-
List<OrderItem>orderItemList = orderItemRepository.findItem();
|
39
|
-
|
40
|
-
List<Item> items = new ArrayList<Item>();
|
41
|
-
//for文でカウント
|
42
|
-
for(int i=0; i< orderItemList.size(); i++) {
|
43
|
-
if (orderItemList.get(i).getItem().getDeleteFlag()==0)
|
44
|
-
items.add(orderItemList.get(i).getItem());
|
45
|
-
}
|
46
|
-
//ページ、ページ遷移処理
|
47
|
-
Page<Item> pages= Convert.listConvertToPage(items,pageable);
|
48
|
-
//ビューに商品情報を渡す処理
|
49
|
-
model.addAttribute("items",pages.getContent());
|
50
|
-
Page<Item>itemList = null;
|
51
|
-
//商品が空の場合は新着順検索
|
52
|
-
if(items.isEmpty()) {
|
53
|
-
itemList= itemRepository.findByDeleteFlagOrderByInsertDateDesc(Constant.NOT_DELETED,pageable);
|
54
|
-
// エンティティ内の検索結果をJavaBeansにコピー
|
55
|
-
List<ItemBean> itemBeanList =
|
56
|
-
BeanCopy.copyEntityToItemBean(itemList.getContent());
|
57
|
-
// 商品情報をViewへ渡す
|
58
|
-
model.addAttribute("items", itemBeanList);
|
59
|
-
model.addAttribute("flg", 1);
|
60
|
-
}
|
61
|
-
return "index";
|
62
|
-
|
63
|
-
```
|
64
|
-
|
65
|
-
|
66
|
-
###コンバーター
|
67
|
-
```
|
68
|
-
|
69
|
-
public class Convert {
|
70
|
-
|
71
|
-
public static <T> Page<T> listConvertToPage(List<T> list, Pageable pageable) {
|
72
|
-
int start = (int)pageable.getOffset();
|
73
|
-
int end= (start + pageable.getPageSize()) > list.size() ? list.size() : ( start + pageable.getPageSize());
|
74
|
-
return new PageImpl<T>(list.subList(start, end), pageable, list.size());
|
75
|
-
}}
|
76
|
-
```
|
77
|
-
### HTML
|
78
|
-
|
79
|
-
```
|
80
|
-
|
81
|
-
|
82
|
-
<!DOCTYPE html>
|
83
|
-
<html xmlns:th="http://www.thymeleaf.org"
|
84
|
-
th:replace="~{common/layout_5block :: layout(~{::body/content()})}">
|
85
|
-
<head>
|
86
|
-
<title>トップ </title>
|
87
|
-
<meta charset="UTF-8" />
|
88
|
-
</head>
|
89
|
-
<body class="user index">
|
90
|
-
<!-- 売れ筋商品の場合表示 -->
|
91
|
-
<div th:if="${flg==1}">
|
92
|
-
<h2 class="title">売れ筋商品</h2>
|
93
|
-
</div>
|
94
|
-
|
95
|
-
<!-- 新着商品の場合表示 -->
|
96
|
-
<div th:if="${flg!=1}">
|
97
|
-
<h2 class="title">新着商品</h2>
|
98
|
-
</div>
|
99
|
-
|
100
|
-
<!-- 商品情報がない場合は無い旨を表示 -->
|
101
|
-
<div th:if="${#lists. isEmpty(items)}">
|
102
|
-
<p th:text="#{itemList.none}" />
|
103
|
-
</div>
|
104
|
-
|
105
|
-
<!-- 商品情報がある場合 -->
|
106
|
-
<!-- 情報の商品画像を表示、または無画像を表示 -->
|
107
|
-
|
108
|
-
<div th:if="!${#lists.isEmpty(items)}">
|
109
|
-
|
110
|
-
<div class="item" th:each="item: ${items}">
|
111
|
-
<span th:if="${item.image != null}">
|
112
|
-
|
113
|
-
<!-- 画像をクリックすることで商品画面に遷移 -->
|
114
|
-
<a th:href="@{/item/detail//{id}(id=${item.id})}">
|
115
|
-
<img th:src="@{/img/{image}(image=${item.image})}"></img></a>
|
116
|
-
</span>
|
117
|
-
|
118
|
-
<span th:if="${item.image == null}">
|
119
|
-
<img th:src="@{/img/common/no_image.jpg}"></img>
|
120
|
-
</span>
|
121
|
-
</div>
|
122
|
-
</div>
|
123
|
-
</body>
|
124
|
-
</html>
|
125
|
-
|
126
|
-
```
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
### 試したこと
|
132
|
-
|
133
|
-
ここに問題に対して試したことを記載してください。
|
134
|
-
|
135
|
-
### 補足情報(FW/ツールのバージョンなど)
|
136
|
-
|
137
|
-
ここにより詳細な情報を記載してください。
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,10 +14,13 @@
|
|
14
14
|
原因と対処法を教えていただけますと、幸いです。
|
15
15
|
|
16
16
|
### 発生している問題・エラーメッセージ
|
17
|
-
エラー
|
17
|
+
実行エラーは出ないのですが、
|
18
|
+
ネットワークで開いてみると
|
19
|
+
表またはビューが存在しません。
|
18
|
-
|
20
|
+
と表示されます。
|
19
21
|
|
20
22
|
|
23
|
+
|
21
24
|
### オーダーアイテムリポジトリ
|
22
25
|
```
|
23
26
|
public interface OrderItemRepository extends JpaRepository<OrderItem, Integer> {
|
1
ミスがあったので修正しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,10 +16,11 @@
|
|
16
16
|
### 発生している問題・エラーメッセージ
|
17
17
|
エラーメッセージも出ないので困っています
|
18
18
|
エラーメッセージ
|
19
|
-
```
|
20
19
|
|
20
|
+
|
21
21
|
### オーダーアイテムリポジトリ
|
22
|
+
```
|
22
|
-
|
23
|
+
public interface OrderItemRepository extends JpaRepository<OrderItem, Integer> {
|
23
24
|
//注文票(オーダーアイテム)の商品を集計し、それをカウントする
|
24
25
|
@Query(value="select OrderItem(item) from OrderItem o group by o.item order by count(o.item) desc", nativeQuery=true)
|
25
26
|
public List<OrderItem> findItem();
|
@@ -27,48 +28,59 @@
|
|
27
28
|
```
|
28
29
|
|
29
30
|
### コントローラ
|
31
|
+
```
|
30
32
|
@RequestMapping(path = "/")
|
31
33
|
public String menu( Model model, Pageable pageable) {
|
32
|
-
//売れ筋順で商品検索
|
34
|
+
//売れ筋順で商品検索
|
33
|
-
List<OrderItem>orderItemList = orderItemRepository.findItem();
|
35
|
+
List<OrderItem>orderItemList = orderItemRepository.findItem();
|
34
36
|
|
35
|
-
List<Item> items = new ArrayList<Item>();
|
37
|
+
List<Item> items = new ArrayList<Item>();
|
36
|
-
//for文でカウント
|
38
|
+
//for文でカウント
|
37
|
-
for(int i=0; i< orderItemList.size(); i++) {
|
39
|
+
for(int i=0; i< orderItemList.size(); i++) {
|
38
|
-
if (orderItemList.get(i).getItem().getDeleteFlag()==0)
|
40
|
+
if (orderItemList.get(i).getItem().getDeleteFlag()==0)
|
39
|
-
items.add(orderItemList.get(i).getItem());
|
41
|
+
items.add(orderItemList.get(i).getItem());
|
40
|
-
}
|
42
|
+
}
|
41
|
-
//ページ、ページ遷移処理
|
43
|
+
//ページ、ページ遷移処理
|
42
|
-
Page<Item> pages= Convert.listConvertToPage(items,pageable);
|
44
|
+
Page<Item> pages= Convert.listConvertToPage(items,pageable);
|
43
|
-
//ビューに商品情報を渡す処理
|
45
|
+
//ビューに商品情報を渡す処理
|
44
|
-
model.addAttribute("items",pages.getContent());
|
46
|
+
model.addAttribute("items",pages.getContent());
|
45
|
-
Page<Item>itemList = null;
|
47
|
+
Page<Item>itemList = null;
|
46
|
-
//商品が空の場合は新着順検索
|
48
|
+
//商品が空の場合は新着順検索
|
47
|
-
if(items.isEmpty()) {
|
49
|
+
if(items.isEmpty()) {
|
48
|
-
itemList=
|
50
|
+
itemList= itemRepository.findByDeleteFlagOrderByInsertDateDesc(Constant.NOT_DELETED,pageable);
|
49
|
-
// エンティティ内の検索結果をJavaBeansにコピー
|
51
|
+
// エンティティ内の検索結果をJavaBeansにコピー
|
52
|
+
List<ItemBean> itemBeanList =
|
50
|
-
|
53
|
+
BeanCopy.copyEntityToItemBean(itemList.getContent());
|
51
|
-
// 商品情報をViewへ渡す
|
54
|
+
// 商品情報をViewへ渡す
|
52
|
-
model.addAttribute("items", itemBeanList);
|
55
|
+
model.addAttribute("items", itemBeanList);
|
53
|
-
model.addAttribute("flg", 1);
|
56
|
+
model.addAttribute("flg", 1);
|
54
|
-
}
|
57
|
+
}
|
55
|
-
return "index";
|
58
|
+
return "index";
|
59
|
+
|
60
|
+
```
|
61
|
+
|
62
|
+
|
56
63
|
###コンバーター
|
64
|
+
```
|
65
|
+
|
57
66
|
public class Convert {
|
58
67
|
|
59
68
|
public static <T> Page<T> listConvertToPage(List<T> list, Pageable pageable) {
|
60
69
|
int start = (int)pageable.getOffset();
|
61
70
|
int end= (start + pageable.getPageSize()) > list.size() ? list.size() : ( start + pageable.getPageSize());
|
62
71
|
return new PageImpl<T>(list.subList(start, end), pageable, list.size());
|
63
|
-
}
|
72
|
+
}}
|
73
|
+
```
|
74
|
+
### HTML
|
64
75
|
|
65
|
-
}
|
66
|
-
|
76
|
+
```
|
77
|
+
|
78
|
+
|
67
79
|
<!DOCTYPE html>
|
68
80
|
<html xmlns:th="http://www.thymeleaf.org"
|
69
81
|
th:replace="~{common/layout_5block :: layout(~{::body/content()})}">
|
70
82
|
<head>
|
71
|
-
<title>トップ
|
83
|
+
<title>トップ </title>
|
72
84
|
<meta charset="UTF-8" />
|
73
85
|
</head>
|
74
86
|
<body class="user index">
|
@@ -107,9 +119,8 @@
|
|
107
119
|
</div>
|
108
120
|
</body>
|
109
121
|
</html>
|
122
|
+
|
110
123
|
```
|
111
|
-
コード
|
112
|
-
```
|
113
124
|
|
114
125
|
|
115
126
|
|