質問編集履歴
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,45 +64,7 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
-
同じような形で
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
ListのProfileで登録ユーザー一覧に画像を表示したい場合
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
```java
|
76
|
-
|
77
|
-
@GetMapping(path = "usersList")
|
78
|
-
|
79
|
-
String usersList(@RequestParam Integer genderId, Model model){
|
80
|
-
|
81
|
-
List<Profile> profile = profileService.findUsers(genderId);
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
//画像ファイルをBASE64形式でエンコード
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
model.addAttribute("profile", profile);
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
.
|
94
|
-
|
95
|
-
.
|
96
|
-
|
97
|
-
.
|
98
|
-
|
99
|
-
.
|
100
|
-
|
101
|
-
return "konkatsu/profileList";
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
```
|
106
68
|
|
107
69
|
|
108
70
|
|
@@ -155,3 +117,47 @@
|
|
155
117
|
</tr>
|
156
118
|
|
157
119
|
```
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
同じような形で
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
ListのProfileで登録ユーザー一覧に画像を表示したい場合
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
```java
|
132
|
+
|
133
|
+
@GetMapping(path = "usersList")
|
134
|
+
|
135
|
+
String usersList(@RequestParam Integer genderId, Model model){
|
136
|
+
|
137
|
+
List<Profile> profile = profileService.findUsers(genderId);
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
String encodedImage = Base64.getEncoder().encodeToString(profile.getImage());
|
144
|
+
|
145
|
+
System.out.println(encodedImage);
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
model.addAttribute("image", encodedImage);
|
150
|
+
|
151
|
+
model.addAttribute("profile", profile);
|
152
|
+
|
153
|
+
return "konkatsu/profileList";
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
```
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
profile.getImage()でエラーとなってしまいます
|
162
|
+
|
163
|
+
List Profileに格納されているimageを出力したいです
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -74,27 +74,21 @@
|
|
74
74
|
|
75
75
|
```java
|
76
76
|
|
77
|
-
@GetMapping(path = "
|
77
|
+
@GetMapping(path = "usersList")
|
78
78
|
|
79
|
-
|
79
|
+
String usersList(@RequestParam Integer genderId, Model model){
|
80
80
|
|
81
|
-
|
81
|
+
List<Profile> profile = profileService.findUsers(genderId);
|
82
82
|
|
83
83
|
|
84
84
|
|
85
|
-
|
85
|
+
//画像ファイルをBASE64形式でエンコード
|
86
86
|
|
87
87
|
|
88
88
|
|
89
|
-
|
89
|
+
model.addAttribute("profile", profile);
|
90
90
|
|
91
|
-
|
91
|
+
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
92
|
|
99
93
|
.
|
100
94
|
|
@@ -104,9 +98,9 @@
|
|
104
98
|
|
105
99
|
.
|
106
100
|
|
107
|
-
|
101
|
+
return "konkatsu/profileList";
|
108
102
|
|
109
|
-
|
103
|
+
}
|
110
104
|
|
111
105
|
```
|
112
106
|
|
2
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -127,3 +127,37 @@
|
|
127
127
|
String encodedImage = Base64.getEncoder().encodeToString(ここにリストProfileのimageを入れたいのです));
|
128
128
|
|
129
129
|
```
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
```html
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
<tr th:each="profile : ${profile}">
|
140
|
+
|
141
|
+
<!-- エンコードした画像の表示 -->
|
142
|
+
|
143
|
+
<td><img th:src="${'data:image/png;base64,' + image}" width="250" height="150"/></td>
|
144
|
+
|
145
|
+
<td th:text="${profile.name}">山田</td>
|
146
|
+
|
147
|
+
<td th:text="${profile.gender.gender}">山田</td>
|
148
|
+
|
149
|
+
<td th:text="${profile.birthday}">仮</td>
|
150
|
+
|
151
|
+
<td th:text="${profile.height}">仮</td>
|
152
|
+
|
153
|
+
<td th:text="${profile.occupation.occupationName}">仮</td>
|
154
|
+
|
155
|
+
<td th:text="${profile.income}">仮</td>
|
156
|
+
|
157
|
+
<td th:text="${profile.user.mail}">duke</td> <!-- 「profile」オブジェクトがもつ「user」の「mail」を表示 -->
|
158
|
+
|
159
|
+
<td th:text="${profile.text}">仮</td>
|
160
|
+
|
161
|
+
</tr>
|
162
|
+
|
163
|
+
```
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,51 +64,55 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
-
|
67
|
+
同じような形で
|
68
|
-
|
69
|
-
@GetMapping(path = "usersList") // URL は/konkatsu/usersListとなる
|
70
|
-
|
71
|
-
String usersList(@RequestParam Integer genderId, Model model){ //htmlからidとして送られた値を@RequestParamにて取得SpringMVCでは画面に値を渡す為にModelオブジェクトを使用
|
72
|
-
|
73
|
-
List<Profile> profile = profileService.findUsers(genderId);
|
74
68
|
|
75
69
|
|
76
70
|
|
77
|
-
|
71
|
+
ListのProfileで登録ユーザー一覧に画像を表示したい場合
|
78
|
-
|
79
|
-
// String encodedImage = Base64.getEncoder().encodeToString(profile.image());
|
80
|
-
|
81
|
-
//System.out.println(encodedImage);
|
82
72
|
|
83
73
|
|
84
74
|
|
75
|
+
```java
|
85
76
|
|
77
|
+
@GetMapping(path = "myProfile")
|
86
78
|
|
87
|
-
|
79
|
+
String MyList(@RequestParam Integer id, Model model){
|
88
80
|
|
89
|
-
System.out.println(profile.get(0));
|
90
|
-
|
91
|
-
|
81
|
+
Profile profile = profileService.findProfile(id);
|
92
|
-
|
93
|
-
System.out.println(encodedImage);
|
94
82
|
|
95
83
|
|
96
84
|
|
97
|
-
|
85
|
+
String encodedImage =
|
98
|
-
|
99
|
-
model.addAttribute("profile", profile); //第一引数はThymeleafで取り出す時に使う名前、第二引数はThymeleafに渡したいオブジェクトを指定
|
100
|
-
|
101
|
-
return "konkatsu/profileList"; //遷移する画面の名前
|
102
|
-
|
103
|
-
}
|
104
86
|
|
105
87
|
|
88
|
+
|
89
|
+
Base64.getEncoder().encodeToString(???);
|
90
|
+
|
91
|
+
//ここで画像ファイルをBASE64形式でエンコードしたいです
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
.
|
100
|
+
|
101
|
+
.
|
102
|
+
|
103
|
+
.
|
104
|
+
|
105
|
+
.
|
106
|
+
|
107
|
+
return "konkatsu/myProfile";
|
108
|
+
|
109
|
+
}
|
106
110
|
|
107
111
|
```
|
108
112
|
|
109
113
|
|
110
114
|
|
111
|
-
|
115
|
+
|
112
116
|
|
113
117
|
|
114
118
|
|