From 2d124cd28167d09082aed2da35a63fe866b0090e Mon Sep 17 00:00:00 2001
From: EuichanJeong <dmlcks5791@ajou.ac.kr>
Date: Wed, 2 Apr 2025 17:41:26 +0900
Subject: [PATCH] add product_list.html

---
 .../demo/controller/TestController.java       | 30 ++++++++++
 src/main/resources/static/product_list.html   | 58 +++++++++++++++++++
 2 files changed, 88 insertions(+)
 create mode 100644 src/main/resources/static/product_list.html

diff --git a/src/main/java/com/example/demo/controller/TestController.java b/src/main/java/com/example/demo/controller/TestController.java
index 67559cd..1c28348 100644
--- a/src/main/java/com/example/demo/controller/TestController.java
+++ b/src/main/java/com/example/demo/controller/TestController.java
@@ -5,6 +5,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 
 
@@ -24,4 +25,33 @@ public class TestController {
 
     }
 
+    @RequestMapping(value = "/productlist", method = RequestMethod.GET)
+    public String productList(){
+
+        JsonObject obj1 = new JsonObject();
+        obj1.addProperty("item_nm", "수제 햄버거");
+        obj1.addProperty("item_detail", "소고기 패티와 토마토가 들어 있는 햄버거");
+        obj1.addProperty("item_reg_date", "2022/04/22");
+        obj1.addProperty("item_price", "4000");
+
+        JsonObject obj2 = new JsonObject();
+        obj2.addProperty("item_nm", "카레라이스");
+        obj2.addProperty("item_detail", "매운 3분 카레라이스");
+        obj2.addProperty("item_reg_date", "2022/03/10");
+        obj2.addProperty("item_price", "8000");
+
+        JsonObject obj3 = new JsonObject();
+        obj3.addProperty("item_nm", "라면");
+        obj3.addProperty("item_detail", "소고기 라면");
+        obj3.addProperty("item_reg_date", "2021/09/10");
+        obj3.addProperty("item_price", "1500");
+
+        JsonArray infoArray = new JsonArray();
+        infoArray.add(obj1);
+        infoArray.add(obj2);
+        infoArray.add(obj3);
+
+        return infoArray.toString();
+    }
+
 }
diff --git a/src/main/resources/static/product_list.html b/src/main/resources/static/product_list.html
new file mode 100644
index 0000000..c3c7791
--- /dev/null
+++ b/src/main/resources/static/product_list.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Product</title>
+    <link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css">
+    <script src="/webjars/jquery/3.6.0/jquery.min.js"></script>
+    <script src="/webjars/popper.js/2.9.3/umd/popper.min.js"></script>
+    <script src="/webjars/bootstrap/5.1.3/js/bootstrap.min.js"></script>
+    <script>
+        $(document).ready(function(){
+          $("button").click(function(){
+
+            $.ajax({
+
+              type: 'GET',
+              url: '/productlist',
+              success: function(data){
+                var array = JSON.parse(data);
+                for(i=0; i < array.length; i++){
+                    var obj = array[i];
+                    html = '';
+                    html += '<tr>';
+                    html += '<td>' + obj.item_nm + '</td>'
+                    html += '<td>' + obj.item_detail + '</td>'
+                    html += '<td>' + obj.item_reg_date + '</td>'
+                    html += '<td>' + obj.item_price + '</td>'
+                    html += '</tr>';
+                    $("#tableBody").append(html);
+                }
+
+              }
+
+            });
+
+
+          });
+        });
+    </script>
+
+</head>
+<body>
+<h1>상품 데이터 목록 출력</h1>
+<button>조회</button>
+<table class="table table-hover">
+    <thead class="thead-dark">
+        <tr>
+            <th>상품이름</th>
+            <th>상품상세설명</th>
+            <th>상품등록일</th>
+            <th>상품가격</th>
+        </tr>
+    </thead>
+    <tbody id="tableBody">
+    </tbody>
+</table>
+</body>
+</html>
-- 
GitLab