Skip to content

Commit 8d2cdca

Browse files
committed
제품 상세 페이지 작성
1 parent 4d9a52f commit 8d2cdca

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

routes/admin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ router.post('/products/write', function (req, res) {
3333
});
3434
});
3535

36+
router.get('/products/detail/:id', function(req, res){
37+
//url 에서 변수 값을 받아올떈 req.params.id 로 받아온다
38+
ProductsModel.findOne({'id': req.params.id},function(err, product){//findOne(조건,콜백함수)는 한 줄의 데이터만 가져와
39+
res.render('admin/productsDetail', {product:product});
40+
});
41+
});
42+
3643
module.exports = router;

views/admin/products.ejs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
<table class="table table-bordered table-hover">
44
<tr>
5-
<th>제목</th>
5+
<th>상품명</th>
66
<th>작성일</th>
77
<th>가격(원)</th>
88
<th>삭제</th>
99
</tr>
1010
<% products.forEach( function(product){ %>
1111
<tr>
12-
<td><%=product.name%></td>
12+
<td>
13+
<a href="/admin/products/detail/<%=product.id%>">
14+
<%=product.name%>
15+
</a>
16+
</td>
1317
<td>
1418
<%=product.getDate.year%>
1519
<%=product.getDate.month%>

views/admin/productsDetail.ejs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<% include ../header.ejs %>
2+
3+
4+
5+
<div class="panel panel-default">
6+
<div class="panel-heading">
7+
<%=product.name%>
8+
</div>
9+
<div class="panel-body">
10+
<div style="padding-bottom: 10px">
11+
작성일 :
12+
<%=product.getDate.year%>
13+
<%=product.getDate.month%>
14+
<%=product.getDate.day%>
15+
</div>
16+
17+
<%=product.description%>
18+
19+
20+
</div>
21+
</div>
22+
23+
<a href="/admin/products" class="btn btn-default">목록으로</a>
24+
<a href="/admin/products/edit/<%=product.id%>" class="btn btn-primary">수정</a>
25+
26+
27+
28+
29+
30+
31+
<% include ../footer.ejs %>

0 commit comments

Comments
 (0)