質問編集履歴
4
添付の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -851,3 +851,21 @@
|
|
851
851
|
|
852
852
|
|
853
853
|
ここにより詳細な情報を記載してください。
|
854
|
+
|
855
|
+
|
856
|
+
|
857
|
+
※ブラウザエラー
|
858
|
+
|
859
|
+
![イメージ説明](591ea7de55f51f45fc9bfe183a9a24e5.jpeg)
|
860
|
+
|
861
|
+
|
862
|
+
|
863
|
+
※stsエラー①
|
864
|
+
|
865
|
+
![イメージ説明](89128fb62b2756b01ae0a8b268e50fa1.jpeg)
|
866
|
+
|
867
|
+
|
868
|
+
|
869
|
+
※stsエラー②
|
870
|
+
|
871
|
+
![イメージ説明](3e6bed0203951830388e76b4e7b82bd6.jpeg)
|
3
ご指摘いただいたものを修正いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
最終的には、localhostに反映した商品名等の表示・購入btnのクリック・ 履歴表示のクリックで開発者ツールに表示されるようにしたいです。
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
お世話になります。
|
8
|
-
|
9
3
|
現在、簡易的なショッピングサイトを作成しております。
|
10
4
|
|
11
5
|
そこで発生したエラーについてですが、どのように修正をすればよいのか分からず、お力をいただければと思い投稿いたしました。
|
@@ -20,11 +14,7 @@
|
|
20
14
|
|
21
15
|
```
|
22
16
|
|
23
|
-
|
17
|
+
添付参照
|
24
|
-
|
25
|
-
spring tool :: [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]")
|
26
|
-
|
27
|
-
|
28
18
|
|
29
19
|
```
|
30
20
|
|
@@ -44,7 +34,7 @@
|
|
44
34
|
|
45
35
|
|
46
36
|
|
47
|
-
import java.util.List;
|
37
|
+
import java.util.List;略
|
48
38
|
|
49
39
|
|
50
40
|
|
@@ -178,7 +168,7 @@
|
|
178
168
|
|
179
169
|
【Goods.java】
|
180
170
|
|
181
|
-
package xxxx.model.domain;
|
171
|
+
package xxxxx.model.domain;
|
182
172
|
|
183
173
|
|
184
174
|
|
@@ -202,91 +192,635 @@
|
|
202
192
|
|
203
193
|
private List<Purchase> purchaseList;
|
204
194
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
p
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
p
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
195
|
+
|
196
|
+
|
197
|
+
以下文字数オーバーのため略(getter/setter)
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
```
|
202
|
+
|
203
|
+
```
|
204
|
+
|
205
|
+
【Purchase.java】
|
206
|
+
|
207
|
+
package xxxxx.practice.model.domain;
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
import java.sql.Timestamp;
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
public class Purchase {
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
private long id;
|
220
|
+
|
221
|
+
private long userId;
|
222
|
+
|
223
|
+
private long goodsId;
|
224
|
+
|
225
|
+
private long itemCount;
|
226
|
+
|
227
|
+
private long total;
|
228
|
+
|
229
|
+
private Timestamp createdAt;
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
以下文字数オーバーのため略(getter/setter)
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
```
|
240
|
+
|
241
|
+
```
|
242
|
+
|
243
|
+
【User.java】
|
244
|
+
|
245
|
+
package xxxxx.practice.model.domain;
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
public class User {
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
private long id;
|
254
|
+
|
255
|
+
private String userName;
|
256
|
+
|
257
|
+
private String password;
|
258
|
+
|
259
|
+
private String fullName;
|
260
|
+
|
261
|
+
private int isAdmin;
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
以下文字数オーバーのため略(getter/setter)
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
```
|
270
|
+
|
271
|
+
```
|
272
|
+
|
273
|
+
【HistoryDto.java】
|
274
|
+
|
275
|
+
package xxxxx.practice.model.domain.dto;
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
import java.sql.Timestamp;略
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
public class HistoryDto {
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
private long id;
|
288
|
+
|
289
|
+
private long userId;
|
290
|
+
|
291
|
+
private long goodsId;
|
292
|
+
|
293
|
+
private String goodsName;
|
294
|
+
|
295
|
+
private long itemCount;
|
296
|
+
|
297
|
+
private long total;
|
298
|
+
|
299
|
+
private Timestamp createdAt;
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
public HistoryDto() {}
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
public HistoryDto(Goods goods) {
|
308
|
+
|
309
|
+
Purchase p = goods.getPurchaseList().get(0);
|
310
|
+
|
311
|
+
this.setId(p.getId());
|
312
|
+
|
313
|
+
this.setUserId(p.geUsertId());
|
314
|
+
|
315
|
+
this.setGoodsId(p.getGoodsId());
|
316
|
+
|
317
|
+
this.setGoodsName(goods.getGoodsName());
|
318
|
+
|
319
|
+
this.setItemCount(p.getItemCount());
|
320
|
+
|
321
|
+
this.setTotal(p.getTotal());
|
322
|
+
|
323
|
+
this.setCreatedAt(p.getCreatedAt());
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
268
328
|
|
269
329
|
}
|
270
330
|
|
271
331
|
|
272
332
|
|
273
|
-
|
274
|
-
|
275
|
-
```
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
```
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
333
|
+
以下文字数オーバーのため略(getter/setter)
|
334
|
+
|
335
|
+
```
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
```
|
340
|
+
|
341
|
+
【HistoryForm.java】
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
package xxxxx.practice.model.form;
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
import java.io.Serializable;
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
public class HistoryForm implements Serializable {
|
354
|
+
|
355
|
+
private static final long serialVersionUID = 1L;
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
private String userId;
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
以下文字数オーバーのため略(getter/setter)
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
```
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
```
|
372
|
+
|
373
|
+
【PurchaseForm.java】
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
package xxxxx.practice.model.form;
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
import java.io.Serializable;
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
public class PurchaseForm implements Serializable {
|
386
|
+
|
387
|
+
private static final long serialVersionUID = 1L;
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
private long userId;
|
392
|
+
|
393
|
+
private long goodsId;
|
394
|
+
|
395
|
+
private long itemCount;
|
396
|
+
|
397
|
+
private long total;
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
以下文字数オーバーのため略(getter/setter)
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
```
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
```
|
410
|
+
|
411
|
+
【GoodsMapper.java】
|
412
|
+
|
413
|
+
package 〃.practice.model.mapper;
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
import java.util.List;
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
import org.apache.ibatis.annotations.Delete;略
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
@Mapper
|
426
|
+
|
427
|
+
public interface GoodsMapper {
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
@Select("SELECT * FROM goods")
|
432
|
+
|
433
|
+
List<Goods> findAll();
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
@Delete("DELETE FROM goods WHERE Id = #{id}")
|
438
|
+
|
439
|
+
boolean deleteById(long id);
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
}
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
```
|
450
|
+
|
451
|
+
```
|
452
|
+
|
453
|
+
【PurchaseMapper.java】
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
package 〃.practice.model.mapper;
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
import java.util.List;
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
import org.apache.ibatis.annotations.Insert;略
|
466
|
+
|
467
|
+
@Mapper
|
468
|
+
|
469
|
+
public interface PurchaseMapper {
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
List<HistoryDto> findHistory(@Param("userId") String userId);
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
@Insert("INSERT INTO purchase (user_id, goods_id, item_count, total)" +
|
478
|
+
|
479
|
+
"VALUES (#{userId}, #{goodsId}, #{itemCount}, #{total})")
|
480
|
+
|
481
|
+
@Options(useGeneratedKeys=true, keyProperty="id")
|
482
|
+
|
483
|
+
void insert(Purchase purchase);
|
484
|
+
|
485
|
+
}
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
```
|
490
|
+
|
491
|
+
```
|
492
|
+
|
493
|
+
【UserMapper.java】
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
package 〃.practice.model.mapper;
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
import java.util.List;略
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
@Mapper
|
506
|
+
|
507
|
+
public interface UserMapper {
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
List<User> findByUserNameAndPassword (
|
512
|
+
|
513
|
+
@Param("userName") String userName,
|
514
|
+
|
515
|
+
@Param("password") String password);
|
516
|
+
|
517
|
+
}
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
```
|
522
|
+
|
523
|
+
```
|
524
|
+
|
525
|
+
【PurchaseMapper.xml】
|
526
|
+
|
527
|
+
|
528
|
+
|
529
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
530
|
+
|
531
|
+
<!DOCTYPE html
|
532
|
+
|
533
|
+
PUBLIC "-//mybatis.org//DTO Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
534
|
+
|
535
|
+
<mapper
|
536
|
+
|
537
|
+
namespace="〃.practice.model.mapper.PurchaseMapper">
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
<select id="findHistory" resultType="〃.practice.model.domain.dto.HistoryDto">
|
542
|
+
|
543
|
+
SELECT p.id, p.user_id, p.goods_id, p.goods_name, p.item_count, p.total, p.created_at
|
544
|
+
|
545
|
+
FROM purchase p
|
546
|
+
|
547
|
+
INNER JOIN goods g
|
548
|
+
|
549
|
+
ON p.goods_id = g.id
|
550
|
+
|
551
|
+
WHERE created_at = (
|
552
|
+
|
553
|
+
SELECT MAX(created_at) FROM purchase p WHERE p.user_id = #{userId})
|
554
|
+
|
555
|
+
</select>
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
</mapper>
|
560
|
+
|
561
|
+
```
|
562
|
+
|
563
|
+
```
|
564
|
+
|
565
|
+
【UserMapper.xml】
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
570
|
+
|
571
|
+
<!DOCTYPE html
|
572
|
+
|
573
|
+
PUBLIC "-//mybatis.org//DTO Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
574
|
+
|
575
|
+
<mapper
|
576
|
+
|
577
|
+
namespace="〃.practice.model.mapper.UserMapper">
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
<select id="findByUserNameAndPassword"
|
582
|
+
|
583
|
+
resultType="〃.practice.model.domain.User">
|
584
|
+
|
585
|
+
SELECT * FROM user WHERE user_name = #{userName} AND password = #{password}
|
586
|
+
|
587
|
+
</select>
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
</mapper>
|
592
|
+
|
593
|
+
```
|
594
|
+
|
595
|
+
```
|
596
|
+
|
597
|
+
【index.html】
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
<!DOCTYPE html>
|
602
|
+
|
603
|
+
<html xmlns:th="http://www.thymeleaf.org">
|
604
|
+
|
605
|
+
<head>
|
606
|
+
|
607
|
+
<meta charset="UTF-8" />
|
608
|
+
|
609
|
+
<title>ショッピングサイト(仮)</title>
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
<style>
|
614
|
+
|
615
|
+
td:nth-child(1).td:nth-child(3) {
|
616
|
+
|
617
|
+
text-align: right;
|
618
|
+
|
619
|
+
}
|
620
|
+
|
621
|
+
input[type=number] {
|
622
|
+
|
623
|
+
width: 50px;
|
624
|
+
|
625
|
+
text-align: right;
|
626
|
+
|
627
|
+
}
|
628
|
+
|
629
|
+
</style>
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
<script src="http://code.jquery.com/jquery-3.4.1.min.js"></script>
|
634
|
+
|
635
|
+
<script>
|
636
|
+
|
637
|
+
$(() => {
|
638
|
+
|
639
|
+
$('button.purchase').on('click', buy);
|
640
|
+
|
641
|
+
$('button#history').on('click', showHistory);
|
642
|
+
|
643
|
+
});
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
let buy = (event) => {
|
648
|
+
|
649
|
+
let targetTr = $(event.target).parent().parent();
|
650
|
+
|
651
|
+
let tdList = $(targetTr).find('td');
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
let total = Number($(tdList[3]).find('input').val()) * Number($(tdList[2]).text());
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
let data = {
|
660
|
+
|
661
|
+
"userId": $('#hiddenUserId').val(),
|
662
|
+
|
663
|
+
"goodsId": $(tdList[0]).text(),
|
664
|
+
|
665
|
+
"itemCount": $(tdList[3]).find('input').val(),
|
666
|
+
|
667
|
+
"total": total,
|
668
|
+
|
669
|
+
};
|
670
|
+
|
671
|
+
|
672
|
+
|
673
|
+
$.ajax ({
|
674
|
+
|
675
|
+
type: 'POST',
|
676
|
+
|
677
|
+
url: '/practice/api/purchase',
|
678
|
+
|
679
|
+
data: JSON.stringify(data),
|
680
|
+
|
681
|
+
contentType: 'application/json',
|
682
|
+
|
683
|
+
datatype: 'json',
|
684
|
+
|
685
|
+
scriptCharset: 'utf-8'
|
686
|
+
|
687
|
+
})
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
.then(
|
692
|
+
|
693
|
+
(result) => {
|
694
|
+
|
695
|
+
alert('購入');
|
696
|
+
|
697
|
+
}, () => {
|
698
|
+
|
699
|
+
console.error('Error: ajax connection failed.');
|
700
|
+
|
701
|
+
}
|
702
|
+
|
703
|
+
);
|
704
|
+
|
705
|
+
};
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
|
710
|
+
|
711
|
+
let showHistory = (event) => {
|
712
|
+
|
713
|
+
$.ajax({
|
714
|
+
|
715
|
+
type: 'POST',
|
716
|
+
|
717
|
+
url: '/practice/api/history',
|
718
|
+
|
719
|
+
data: JSON.stringify({
|
720
|
+
|
721
|
+
"userId": $('#hiddenUserId').val(),
|
722
|
+
|
723
|
+
}),
|
724
|
+
|
725
|
+
contentType: 'application/json',
|
726
|
+
|
727
|
+
datatype: 'json',
|
728
|
+
|
729
|
+
scriptCharset: 'utf-8'
|
730
|
+
|
731
|
+
})
|
732
|
+
|
733
|
+
}
|
734
|
+
|
735
|
+
|
736
|
+
|
737
|
+
.then(
|
738
|
+
|
739
|
+
(result) => {
|
740
|
+
|
741
|
+
let purchaseList = JSON.parse(result);
|
742
|
+
|
743
|
+
purchaseList.map((v) => {
|
744
|
+
|
745
|
+
console.log(v.userId);
|
746
|
+
|
747
|
+
console.log(v.goodsId);
|
748
|
+
|
749
|
+
console.log(v.goodsName);
|
750
|
+
|
751
|
+
console.log(v.createdAt);
|
752
|
+
|
753
|
+
})
|
754
|
+
|
755
|
+
},
|
756
|
+
|
757
|
+
() => {
|
758
|
+
|
759
|
+
console.error('Error: ajax connection failed.');
|
760
|
+
|
761
|
+
}
|
762
|
+
|
763
|
+
);
|
764
|
+
|
765
|
+
};
|
766
|
+
|
767
|
+
</script>
|
768
|
+
|
769
|
+
</head>
|
770
|
+
|
771
|
+
<body>
|
772
|
+
|
773
|
+
|
774
|
+
|
775
|
+
<table id="goodsListTable">
|
776
|
+
|
777
|
+
<thead>
|
778
|
+
|
779
|
+
<tr>
|
780
|
+
|
781
|
+
<th>xxx</th><th>xxx</th><th>xxx</th><th>xxx</th><th>xxx</th>
|
782
|
+
|
783
|
+
</tr>
|
784
|
+
|
785
|
+
</thead>
|
786
|
+
|
787
|
+
|
788
|
+
|
789
|
+
<tbody>
|
790
|
+
|
791
|
+
<tr th:each="item: ${goodsList}">
|
792
|
+
|
793
|
+
<td th:text="${item.id}"/>
|
794
|
+
|
795
|
+
<td th:text="${item.goodsName}"/>
|
796
|
+
|
797
|
+
<td th:text="${item.price}"/>
|
798
|
+
|
799
|
+
<td><input type="number" class="count" value="0" /></td>
|
800
|
+
|
801
|
+
<td><button class="purchase">購入</button></td>
|
802
|
+
|
803
|
+
</tr>
|
804
|
+
|
805
|
+
</tbody>
|
806
|
+
|
807
|
+
|
808
|
+
|
809
|
+
</table>
|
810
|
+
|
811
|
+
|
812
|
+
|
813
|
+
<button id="history">履歴</button>
|
814
|
+
|
815
|
+
|
816
|
+
|
817
|
+
<input type="hidden" id="hiddenUserId" th:value="${user.id}" />
|
818
|
+
|
819
|
+
|
820
|
+
|
821
|
+
</body>
|
822
|
+
|
823
|
+
</html>
|
290
824
|
|
291
825
|
```
|
292
826
|
|
2
ご指摘いただいたものを、全て修正いたしました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
簡易的なショッピングサイト
|
1
|
+
簡易的なショッピングサイト【初心者質問】
|
test
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
+
最終的には、localhostに反映した商品名等の表示・購入btnのクリック・ 履歴表示のクリックで開発者ツールに表示されるようにしたいです。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
お世話になります。
|
8
|
+
|
9
|
+
現在、簡易的なショッピングサイトを作成しております。
|
10
|
+
|
11
|
+
そこで発生したエラーについてですが、どのように修正をすればよいのか分からず、お力をいただければと思い投稿いたしました。
|
12
|
+
|
3
|
-
|
13
|
+
よろしくお願いいたします。
|
4
|
-
|
5
|
-
|
14
|
+
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
15
|
+
|
10
|
-
|
11
|
-
下記エラーが表示されたものの、具体的にどこを見直せばよいかわからないので、お力を貸していただければと思います。
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
ブラウザのコンソールでは『GET http://localhost:8080/practice 404 practice:1 』と表示されました。
|
16
|
-
|
17
|
-
404 => 該当アドレスのページがない、またはそのサーバーが落ちている状態
|
18
16
|
|
19
17
|
### 発生している問題・エラーメッセージ
|
20
18
|
|
@@ -22,11 +20,11 @@
|
|
22
20
|
|
23
21
|
```
|
24
22
|
|
25
|
-
ブラウザのコンソール
|
26
|
-
|
27
|
-
|
23
|
+
ブラウザ: GET http://localhost:8080/practice/ 404
|
28
|
-
|
24
|
+
|
29
|
-
sts
|
25
|
+
spring tool :: [THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]")
|
26
|
+
|
27
|
+
|
30
28
|
|
31
29
|
```
|
32
30
|
|
@@ -36,173 +34,237 @@
|
|
36
34
|
|
37
35
|
|
38
36
|
|
37
|
+
```ここに言語名を入力
|
38
|
+
|
39
|
+
【IndexController】
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
package xxxxx.practice.controlle;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
import java.util.List;以下略
|
48
|
+
|
49
|
+
|
50
|
+
|
39
|
-
|
51
|
+
@Controller
|
52
|
+
|
40
|
-
|
53
|
+
@RequestMapping("/practice")
|
54
|
+
|
55
|
+
public class IndexController {
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
@Autowired
|
60
|
+
|
61
|
+
UserMapper userMapper;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
@Autowired
|
66
|
+
|
67
|
+
GoodsMapper goodsMapper;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
@Autowired
|
72
|
+
|
73
|
+
PurchaseMapper purchaseMapper;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
Gson gson = new Gson();
|
78
|
+
|
79
|
+
|
80
|
+
|
41
|
-
|
81
|
+
@RequestMapping("practice")
|
82
|
+
|
42
|
-
|
83
|
+
public String index(Model m) {
|
84
|
+
|
43
|
-
|
85
|
+
String userName = "taro";
|
86
|
+
|
87
|
+
String password = "taropw";
|
88
|
+
|
89
|
+
List<User> users = userMapper.findByUserNameAndPassword(userName, password);
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
User user = new User();
|
94
|
+
|
95
|
+
if(users != null && users.size() > 0) {
|
96
|
+
|
97
|
+
user = users.get(0);
|
98
|
+
|
99
|
+
System.out.println(user.getFullName());
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
m.addAttribute("user", user);
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
List<Goods> goodsList = goodsMapper.findAll();
|
108
|
+
|
109
|
+
if(goodsList != null && goodsList.size() > 0) {
|
110
|
+
|
111
|
+
m.addAttribute("goodsList", goodsList);
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
return "index";
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
@ResponseBody
|
124
|
+
|
125
|
+
@PostMapping("/api/purchase")
|
126
|
+
|
127
|
+
public String purchaseApi(@RequestBody PurchaseForm f) {
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
Purchase p = new Purchase();
|
132
|
+
|
133
|
+
p.setUserId(f.getUserId());
|
134
|
+
|
135
|
+
p.setGoodsId(f.getGoodsId());
|
136
|
+
|
137
|
+
p.setItemCount(f.getItemCount());
|
138
|
+
|
139
|
+
p.setTotal(f.getTotal());
|
140
|
+
|
141
|
+
purchaseMapper.insert(p);
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
return "1";
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
@ResponseBody
|
152
|
+
|
153
|
+
@PostMapping("/api/history")
|
154
|
+
|
155
|
+
public String historyApi(@RequestBody HistoryForm form) {
|
156
|
+
|
157
|
+
String userId = form.getUserId();
|
158
|
+
|
159
|
+
List<HistoryDto> history = purchaseMapper.findHistory(userId);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
return gson.toJson(history);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
```
|
178
|
+
|
179
|
+
【Goods.java】
|
180
|
+
|
181
|
+
package xxxx.model.domain;
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
import java.sql.Timestamp;
|
44
186
|
|
45
187
|
import java.util.List;
|
46
188
|
|
47
189
|
|
48
190
|
|
49
|
-
i
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
i
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
i
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
i
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
i
|
84
|
-
|
85
|
-
i
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
public cl
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
Purchase
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
String password = "taropw";
|
128
|
-
|
129
|
-
List<User> users = userMapper.findByUserNameAndPassword(userName, password);
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
User user = new User();
|
134
|
-
|
135
|
-
if(users != null && users.size() > 0) {
|
136
|
-
|
137
|
-
user = users.get(0);
|
138
|
-
|
139
|
-
System.out.println(user.getFullName());
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
m.addAttribute("user", user);
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
List<Goods> goodsList = goodsMapper.findAll();
|
148
|
-
|
149
|
-
if(goodsList != null && goodsList.size() > 0) {
|
150
|
-
|
151
|
-
m.addAttribute("goodsList", goodsList);
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
return "index";
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
@ResponseBody
|
164
|
-
|
165
|
-
@PostMapping("/api/purchase")
|
166
|
-
|
167
|
-
public String purchaseApi(@RequestBody PurchaseForm f) {
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
Purchase p = new Purchase();
|
172
|
-
|
173
|
-
p.setUserId(f.getUserId());
|
174
|
-
|
175
|
-
p.setGoodsId(f.getGoodsId());
|
176
|
-
|
177
|
-
p.setItemCount(f.getItemCount());
|
178
|
-
|
179
|
-
p.setTotal(f.getTotal());
|
180
|
-
|
181
|
-
purchaseMapper.insert(p);
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
return "1";
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
@ResponseBody
|
192
|
-
|
193
|
-
@PostMapping("/api/history")
|
194
|
-
|
195
|
-
public String historyApi(@RequestBody HistoryForm form) {
|
196
|
-
|
197
|
-
String userId = form.getUserId();
|
198
|
-
|
199
|
-
List<HistoryDto> history = purchaseMapper.findHistory(userId);
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
return gson.toJson(history);
|
204
|
-
|
205
|
-
}
|
191
|
+
public class Goods {
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
private long id;
|
196
|
+
|
197
|
+
private String goodsName;
|
198
|
+
|
199
|
+
private long price;
|
200
|
+
|
201
|
+
private Timestamp updatedAt;
|
202
|
+
|
203
|
+
private List<Purchase> purchaseList;
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
public long getId() {
|
208
|
+
|
209
|
+
return id;
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
public void setId(long id) {
|
214
|
+
|
215
|
+
this.id = id;
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
public String getGoodsName() {
|
220
|
+
|
221
|
+
return goodsName;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
public void setGoodsName(String goodsName) {
|
226
|
+
|
227
|
+
this.goodsName = goodsName;
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
public long getPrice() {
|
232
|
+
|
233
|
+
return price;
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
public void setPrice(long price) {
|
238
|
+
|
239
|
+
this.price = price;
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
public Timestamp getUpdatedAt() {
|
244
|
+
|
245
|
+
return updatedAt;
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
public void setUpdatedAt(Timestamp updatedAt) {
|
250
|
+
|
251
|
+
this.updatedAt = updatedAt;
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
public List<Purchase> getPurchaseList() {
|
256
|
+
|
257
|
+
return purchaseList;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
public void setPurchaseList(List<Purchase> purchaseList) {
|
262
|
+
|
263
|
+
this.purchaseList = purchaseList;
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
206
268
|
|
207
269
|
}
|
208
270
|
|
@@ -210,632 +272,48 @@
|
|
210
272
|
|
211
273
|
```
|
212
274
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
private long itemCount;
|
244
|
-
|
245
|
-
private long total;
|
246
|
-
|
247
|
-
private Timestamp createdAt;
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
public HistoryDto() {}
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
public HistoryDto(Goods goods) {
|
256
|
-
|
257
|
-
Purchase p = goods.getPurchaseList().get(0);
|
258
|
-
|
259
|
-
this.setId(p.getId());
|
260
|
-
|
261
|
-
this.setUserId(p.geUsertId());
|
262
|
-
|
263
|
-
this.setGoodsId(p.getGoodsId());
|
264
|
-
|
265
|
-
this.setGoodsName(goods.getGoodsName());
|
266
|
-
|
267
|
-
this.setItemCount(p.getItemCount());
|
268
|
-
|
269
|
-
this.setTotal(p.getTotal());
|
270
|
-
|
271
|
-
this.setCreatedAt(p.getCreatedAt());
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
※Setter / Getterは略
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
```
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
```form
|
294
|
-
|
295
|
-
【HistoryForm】
|
296
|
-
|
297
|
-
package co.jp.internous.practice.model.form;
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
import java.io.Serializable;
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
public class HistoryForm implements Serializable {
|
306
|
-
|
307
|
-
private static final long serialVersionUID = 1L;
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
private String userId;
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
※Setter / Getterは略
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
【PUrchaseForm】
|
326
|
-
|
327
|
-
import java.io.Serializable;
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
public class PurchaseForm implements Serializable {
|
332
|
-
|
333
|
-
private static final long serialVersionUID = 1L;
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
private long userId;
|
338
|
-
|
339
|
-
private long goodsId;
|
340
|
-
|
341
|
-
private long itemCount;
|
342
|
-
|
343
|
-
private long total;
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
※Setter / Getterは略
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
```
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
```mapper
|
358
|
-
|
359
|
-
【Goods】
|
360
|
-
|
361
|
-
package co.jp.internous.practice.model.mapper;
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
import java.util.List;
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
import org.apache.ibatis.annotations.Delete;
|
370
|
-
|
371
|
-
import org.apache.ibatis.annotations.Mapper;
|
372
|
-
|
373
|
-
import org.apache.ibatis.annotations.Select;
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
import co.jp.internous.practice.model.domain.Goods;
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
@Mapper
|
382
|
-
|
383
|
-
public interface GoodsMapper {
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
@Select("SELECT * FROM goods")
|
388
|
-
|
389
|
-
List<Goods> findAll();
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
@Delete("DELETE FROM goods WHERE Id = #{id}")
|
394
|
-
|
395
|
-
boolean deleteById(long id);
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
【User】
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
package co.jp.internous.practice.model.mapper;
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
import java.util.List;
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
import org.apache.ibatis.annotations.Mapper;
|
416
|
-
|
417
|
-
import org.apache.ibatis.annotations.Param;
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
import co.jp.internous.practice.model.domain.User;
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
@Mapper
|
426
|
-
|
427
|
-
public interface UserMapper {
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
List<User> findByUserNameAndPassword (
|
432
|
-
|
433
|
-
@Param("userName") String userName,
|
434
|
-
|
435
|
-
@Param("password") String password );
|
436
|
-
|
437
|
-
}
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
【Purchase】
|
444
|
-
|
445
|
-
package co.jp.internous.practice.model.mapper;
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
import java.util.List;
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
import org.apache.ibatis.annotations.Insert;
|
454
|
-
|
455
|
-
import org.apache.ibatis.annotations.Mapper;
|
456
|
-
|
457
|
-
import org.apache.ibatis.annotations.Options;
|
458
|
-
|
459
|
-
import org.apache.ibatis.annotations.Param;
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
import co.jp.internous.practice.model.domain.Purchase;
|
464
|
-
|
465
|
-
import co.jp.internous.practice.model.domain.dto.HistoryDto;
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
@Mapper
|
470
|
-
|
471
|
-
public interface PurchaseMapper {
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
List<HistoryDto> findHistory(@Param("userId") String userId);
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
@Insert("INSERT INTO purchase (user_id, goods_id, item_count, total)" +
|
480
|
-
|
481
|
-
"VALUES (#{userId}, #{goodsId}, #{itemCount}, #{total})")
|
482
|
-
|
483
|
-
@Options(useGeneratedKeys=true, keyProperty="id")
|
484
|
-
|
485
|
-
void insert(Purchase purchase);
|
486
|
-
|
487
|
-
}
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
```
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
```domain
|
496
|
-
|
497
|
-
package co.jp.internous.practice.model.domain;
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
import java.sql.Timestamp;
|
502
|
-
|
503
|
-
import java.util.List;
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
public class Goods {
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
private long id;
|
512
|
-
|
513
|
-
private String goodsName;
|
514
|
-
|
515
|
-
private long price;
|
516
|
-
|
517
|
-
private Timestamp updatedAt;
|
518
|
-
|
519
|
-
private List<Purchase> purchaseList;
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
※Setter / Getterは略
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
```
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
```xml
|
534
|
-
|
535
|
-
【Purchase】
|
536
|
-
|
537
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
538
|
-
|
539
|
-
<!DOCTYPE html
|
540
|
-
|
541
|
-
PUBLIC "-//mybatis.org//DTO Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
542
|
-
|
543
|
-
<mapper
|
544
|
-
|
545
|
-
namespace="jp.co.internous.practice.model.mapper.PurchaseMapper">
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
<select id="findHistory" resultType="jp.co.internous.practice.model.domain.dto.HistoryDto">
|
550
|
-
|
551
|
-
SELECT p.id, p.user_id, p.goods_id, p.goods_name, p.item_count, p.total, p.created_at
|
552
|
-
|
553
|
-
FROM purchase p
|
554
|
-
|
555
|
-
INNER JOIN goods g
|
556
|
-
|
557
|
-
ON p.goods_id = g.id
|
558
|
-
|
559
|
-
WHERE created_at = (
|
560
|
-
|
561
|
-
SELECT MAX(created_at) FROM purchase p WHERE p.user_id = #{userId})
|
562
|
-
|
563
|
-
</select>
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
</mapper>
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
【UserMapper】
|
572
|
-
|
573
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
574
|
-
|
575
|
-
<!DOCTYPE html
|
576
|
-
|
577
|
-
PUBLIC "-//mybatis.org//DTO Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
578
|
-
|
579
|
-
<mapper
|
580
|
-
|
581
|
-
namespace="jp.co.internous.practice.model.mapper.UserMapper">
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
<select id="findByUserNameAndPassword"
|
586
|
-
|
587
|
-
resultType="jp.co.internous.practice.model.domain.User">
|
588
|
-
|
589
|
-
SELECT * FROM user WHERE user_name = #{userName} AND password = #{password}
|
590
|
-
|
591
|
-
</select>
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
</mapper>
|
596
|
-
|
597
|
-
```
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
```html
|
602
|
-
|
603
|
-
<!DOCTYPE html>
|
604
|
-
|
605
|
-
<html xmlns:th="http://www.thymeleaf.org">
|
606
|
-
|
607
|
-
<head>
|
608
|
-
|
609
|
-
<meta charset="UTF-8" />
|
610
|
-
|
611
|
-
<title>Study Spring boot and Mybatis</title>
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
<style>
|
616
|
-
|
617
|
-
td:nth-child(1).td:nth-child(3) {
|
618
|
-
|
619
|
-
text-align: right;
|
620
|
-
|
621
|
-
}
|
622
|
-
|
623
|
-
input[type=number] {
|
624
|
-
|
625
|
-
width: 50px;
|
626
|
-
|
627
|
-
text-align: right;
|
628
|
-
|
629
|
-
}
|
630
|
-
|
631
|
-
</style>
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
<script src="http://code.jquery.com/jquery-3.4.1.min.js"></script>
|
636
|
-
|
637
|
-
<script>
|
638
|
-
|
639
|
-
$(() => {
|
640
|
-
|
641
|
-
$('button.purchase').on('click', buy);
|
642
|
-
|
643
|
-
$('button#history').on('click', showHistory);
|
644
|
-
|
645
|
-
});
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
let buy = (event) => {
|
650
|
-
|
651
|
-
let targetTr = $(event.target).parent().parent();
|
652
|
-
|
653
|
-
let tdList = $(targetTr).find('td');
|
654
|
-
|
655
|
-
let total = Number($(tdList[3]).find('input').val()) * Number($(tdList[2]).text());
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
let data = {
|
660
|
-
|
661
|
-
"userId": $('#hiddenUserId').val(),
|
662
|
-
|
663
|
-
"goodsId": $(tdList[0]).text(),
|
664
|
-
|
665
|
-
"itemCount": $(tdList[3]).find('input').val(),
|
666
|
-
|
667
|
-
"total": total,
|
668
|
-
|
669
|
-
};
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
$.ajax ({
|
674
|
-
|
675
|
-
type: 'POST',
|
676
|
-
|
677
|
-
url: '/practice/api/purchase',
|
678
|
-
|
679
|
-
data: JSON.stringify(data),
|
680
|
-
|
681
|
-
contentType: 'application/json',
|
682
|
-
|
683
|
-
datatype: 'json',
|
684
|
-
|
685
|
-
scriptCharset: 'utf-8
|
686
|
-
|
687
|
-
})
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
.then(
|
692
|
-
|
693
|
-
(result) => {
|
694
|
-
|
695
|
-
alert('購入しました。');
|
696
|
-
|
697
|
-
}, () => {
|
698
|
-
|
699
|
-
console.error('Error: ajax connection failed.');
|
700
|
-
|
701
|
-
}
|
702
|
-
|
703
|
-
);
|
704
|
-
|
705
|
-
};
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
let showHistory = (event) => {
|
712
|
-
|
713
|
-
$.ajax({
|
714
|
-
|
715
|
-
type: 'POST',
|
716
|
-
|
717
|
-
url: '/practice/api/history',
|
718
|
-
|
719
|
-
data: JSON.stringify({
|
720
|
-
|
721
|
-
"userId": $('#hiddenUserId').val(),
|
722
|
-
|
723
|
-
}),
|
724
|
-
|
725
|
-
contentType: 'application/json',
|
726
|
-
|
727
|
-
datatype: 'json',
|
728
|
-
|
729
|
-
scriptCharset: 'utf-8'
|
730
|
-
|
731
|
-
})
|
732
|
-
|
733
|
-
}
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
.then(
|
738
|
-
|
739
|
-
(result) => {
|
740
|
-
|
741
|
-
let purchaseList = JSON.parse(result);
|
742
|
-
|
743
|
-
purchaseList.map((v) => {
|
744
|
-
|
745
|
-
console.log(v.userId);
|
746
|
-
|
747
|
-
console.log(v.goodsId);
|
748
|
-
|
749
|
-
console.log(v.goodsName);
|
750
|
-
|
751
|
-
console.log(v.createdAt);
|
752
|
-
|
753
|
-
})
|
754
|
-
|
755
|
-
},
|
756
|
-
|
757
|
-
() => {
|
758
|
-
|
759
|
-
console.error('Error: ajax connection failed.');
|
760
|
-
|
761
|
-
}
|
762
|
-
|
763
|
-
);
|
764
|
-
|
765
|
-
};
|
766
|
-
|
767
|
-
</script>
|
768
|
-
|
769
|
-
</head>
|
770
|
-
|
771
|
-
<body>
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
<table id="goodsListTable">
|
776
|
-
|
777
|
-
<thead>
|
778
|
-
|
779
|
-
<tr>
|
780
|
-
|
781
|
-
<th>ID</th><th>商品名</th><th>価格</th><th>注文数</th><th>カート</th>
|
782
|
-
|
783
|
-
</tr>
|
784
|
-
|
785
|
-
</thead>
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
<tbody>
|
790
|
-
|
791
|
-
<tr th:each="item: ${goodsList}">
|
792
|
-
|
793
|
-
<td th:text="${item.id}"/>
|
794
|
-
|
795
|
-
<td th:text="${item.goodsName}"/>
|
796
|
-
|
797
|
-
<td th:text="${item.price}"/>
|
798
|
-
|
799
|
-
<td><input type="number" class="count" value="0" /></td>
|
800
|
-
|
801
|
-
<td><button class="purchase">購入</button></td>
|
802
|
-
|
803
|
-
</tr>
|
804
|
-
|
805
|
-
</tbody>
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
</table>
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
<button id="history">履歴</button>
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
<input type="hidden" id="hiddenUserId" th:value="${user.id}" />
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
</body>
|
822
|
-
|
823
|
-
</html>
|
824
|
-
|
825
|
-
```
|
275
|
+
```
|
276
|
+
|
277
|
+
【Purchase.java】
|
278
|
+
|
279
|
+
```
|
280
|
+
|
281
|
+
```
|
282
|
+
|
283
|
+
【User.java】
|
284
|
+
|
285
|
+
```
|
286
|
+
|
287
|
+
```
|
288
|
+
|
289
|
+
【User.java】
|
290
|
+
|
291
|
+
```
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
826
304
|
|
827
305
|
### 試したこと
|
828
306
|
|
829
307
|
|
830
308
|
|
831
|
-
|
309
|
+
誤字脱字の確認。エラーについて調べるものの、いまいちわかりませんでした。
|
832
|
-
|
833
|
-
何卒宜しくお願い致します。
|
834
310
|
|
835
311
|
|
836
312
|
|
837
313
|
### 補足情報(FW/ツールのバージョンなど)
|
838
314
|
|
315
|
+
stsのプロジェクトは:spring web/ thymeleaf/My SQL Driver/MyBatis Framework を選択しております。
|
316
|
+
|
839
317
|
|
840
318
|
|
841
319
|
ここにより詳細な情報を記載してください。
|
1
題名の変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
簡易的なショッピングサイト
|
test
CHANGED
File without changes
|