質問編集履歴
1
ああああああああああああああああああ
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
ああああああああああああああああああ
|
body
CHANGED
@@ -1,175 +1,1 @@
|
|
1
|
-
### 前提・実現したいこと
|
2
|
-
登録処理時にBase64でエンコードしてDBにセットしたblob型で定義してある画像を
|
3
|
-
一覧画面取得時にBase64デコードをして、エンティティに定義してあるString型変数に格納をして、一覧画面に表示したいです。
|
4
|
-
### 発生している問題・エラーメッセージ
|
5
|
-
コントローラクラスにてproductInfoList変数でDBから値を取得しているのですが、ここで取得した値をBase64でデコードしてString変数に格納し、一覧画面に出力させる方法がわからないためご教授いただければ幸いです。。
|
6
|
-
### 該当のソースコード
|
7
|
-
コントローラクラス
|
8
|
-
```
|
9
|
-
@Controller
|
10
|
-
public class ProductController {
|
11
|
-
@Autowired
|
12
|
-
ProductMapper productMapper;
|
13
|
-
@Autowired
|
14
|
-
ProductService productService;
|
15
|
-
|
16
|
-
@GetMapping(value = "/product-list" )
|
17
|
-
public String test(Model model) {
|
18
|
-
List<ProductInfo> productInfoList = productMapper.getProductInfoList();
|
19
|
-
int productInfocount = productMapper.getProductInfoCount();
|
20
|
-
ProductInfo product =new ProductInfo();
|
21
|
-
model.addAttribute("productcount", productInfocount);
|
22
|
-
model.addAttribute("productInfo", productInfoList);
|
23
|
-
|
24
|
-
return "product/list";
|
25
|
-
}
|
26
|
-
|
27
|
-
@GetMapping(value = "/product-registration")
|
28
|
-
public String productregistration(@ModelAttribute ProductInfo productInfo) {
|
29
|
-
return "product/registration";
|
30
|
-
}
|
31
|
-
|
32
|
-
@PostMapping(value="/product-registration")
|
33
|
-
public String postproductregistration(@ModelAttribute ProductInfo productInfo) throws IOException {
|
34
|
-
System.out.println(productInfo);
|
35
|
-
productInfo.setProductImg(Base64.encodeBase64(productInfo.getMultiPartFile().getBytes()));
|
36
|
-
System.out.println(productInfo.getProductImg());
|
37
|
-
productService.insertProductInfo(productInfo);
|
38
|
-
return "redirect:/product-list";
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
```
|
43
|
-
エンティティクラス
|
44
|
-
```
|
45
|
-
@Data
|
46
|
-
public class ProductInfo implements Serializable {
|
47
|
-
|
48
|
-
/** シリアルバージョンUID. */
|
49
|
-
private static final long serialVersionUID = -2921497769927755763L;
|
50
|
-
|
51
|
-
/** 商品ID*/
|
52
|
-
private int productID;
|
53
|
-
|
54
|
-
/** 商品名 */
|
55
|
-
private String productName;
|
56
|
-
|
57
|
-
/** ジャンル */
|
58
|
-
private String genre;
|
59
|
-
|
60
|
-
/** メーカー */
|
61
|
-
private String maker;
|
62
|
-
|
63
|
-
/** 商品価格 */
|
64
|
-
private BigDecimal sellingPrice;
|
65
|
-
|
66
|
-
/** 商品概要 */
|
67
|
-
private String productDetail;
|
68
|
-
|
69
|
-
/** 商品画像 */
|
70
|
-
private byte[] productImg;
|
71
|
-
|
72
|
-
/** 削除フラグ */
|
73
|
-
private char DeleteFlg;
|
74
|
-
|
75
|
-
/** 登録日時 */
|
76
|
-
private String InsertDate;
|
77
|
-
|
78
|
-
/** 更新日時 */
|
79
|
-
private String UpdateDate;
|
80
|
-
|
81
|
-
/** 商品画像 入力時 */
|
82
|
-
|
1
|
+
ああああああああああああああああああああああああああああああああああああ
|
83
|
-
|
84
|
-
/**商品画像 表示時 */
|
85
|
-
private String ProductImgOut;
|
86
|
-
}
|
87
|
-
|
88
|
-
```
|
89
|
-
mapperクラス
|
90
|
-
```
|
91
|
-
@Mapper
|
92
|
-
public interface ProductMapper {
|
93
|
-
/**
|
94
|
-
* @return a
|
95
|
-
*/
|
96
|
-
List<ProductInfo> getProductInfoList();
|
97
|
-
|
98
|
-
/**
|
99
|
-
* @return a
|
100
|
-
*/
|
101
|
-
int getProductInfoCount();
|
102
|
-
|
103
|
-
public void insertProductInfo(ProductInfo productInfo);
|
104
|
-
|
105
|
-
}
|
106
|
-
```
|
107
|
-
XML
|
108
|
-
```
|
109
|
-
<mapper namespace="cooking.repository.ProductMapper">
|
110
|
-
<select id="getProductInfoList" resultType="cooking.entity.ProductInfo">
|
111
|
-
SELECT
|
112
|
-
ProductID,
|
113
|
-
Genre,
|
114
|
-
Maker,
|
115
|
-
ProductName,
|
116
|
-
SellingPrice,
|
117
|
-
ProductImg
|
118
|
-
|
119
|
-
FROM
|
120
|
-
ProductInfo
|
121
|
-
|
122
|
-
WHERE
|
123
|
-
DeleteFlg = '0'
|
124
|
-
|
125
|
-
ORDER BY
|
126
|
-
ProductID ASC
|
127
|
-
</select>
|
128
|
-
|
129
|
-
|
130
|
-
<select id="getProductInfoCount" resultType="int">
|
131
|
-
select count(*) from ProductInfo
|
132
|
-
</select>
|
133
|
-
|
134
|
-
<insert id="insertProductInfo" parameterType="cooking.entity.ProductInfo">
|
135
|
-
INSERT INTO ProductInfo (
|
136
|
-
ProductName,
|
137
|
-
Genre,
|
138
|
-
Maker,
|
139
|
-
SellingPrice,
|
140
|
-
ProductDetail,
|
141
|
-
ProductImg,
|
142
|
-
InsertDate,
|
143
|
-
UpdateDate)
|
144
|
-
|
145
|
-
VALUES (
|
146
|
-
#{productName},
|
147
|
-
#{genre},
|
148
|
-
#{maker},
|
149
|
-
#{sellingPrice},
|
150
|
-
#{productDetail},
|
151
|
-
#{productImg},
|
152
|
-
CURRENT_TIMESTAMP(),
|
153
|
-
CURRENT_TIMESTAMP())
|
154
|
-
</insert>
|
155
|
-
</mapper>
|
156
|
-
|
157
|
-
|
158
|
-
```
|
159
|
-
###DB構成
|
160
|
-
+---------------+---------------+------+-----+---------+----------------+
|
161
|
-
| Field | Type | Null | Key | Default | Extra |
|
162
|
-
+---------------+---------------+------+-----+---------+----------------+
|
163
|
-
| ProductID | int | NO | PRI | NULL | auto_increment |
|
164
|
-
| ProductName | varchar(25) | NO | | NULL | |
|
165
|
-
| Genre | char(2) | NO | | NULL | |
|
166
|
-
| Maker | varchar(20) | NO | | NULL | |
|
167
|
-
| SellingPrice | decimal(11,2) | NO | | NULL | |
|
168
|
-
| ProductDetail | varchar(200) | YES | | NULL | |
|
169
|
-
| ProductImg | mediumblob | YES | | NULL | |
|
170
|
-
| DeleteFlg | char(1) | NO | | 0 | |
|
171
|
-
| InsertDate | timestamp(3) | NO | | NULL | |
|
172
|
-
| UpdateDate | timestamp(3) | NO | | NULL | |
|
173
|
-
+---------------+---------------+------+-----+---------+----------------+
|
174
|
-
### 試したこと
|
175
|
-
様々なサイトなどをまわってDBから値を取得してその値をデコードするようなところが特になく、リファレンスなどを確認しましたがやり方がいまいちわからなかったため質問とさせていただきます。
|