chaemino / simple-community-with-db Goto Github PK
View Code? Open in Web Editor NEWDBMS를 활용한 게시판 웹 페이지 구축 (Making Simple Community With NodeJs)
DBMS를 활용한 게시판 웹 페이지 구축 (Making Simple Community With NodeJs)
게시판 목록을 구현한다.
mainpage.ejs
<div class="post-list">
<!-- 게시글 목록 -->
<table id="board">
<thead>
<tr>
<th style="width: 10%; height: 6vh;">게시글 번호</th>
<th style="width: 40%; height: 6vh;">제목</th>
<th style="width: 20%; height: 6vh;">작성 일자</th>
<th style="width: 10%; height: 6vh;">작성자</th>
</tr>
<thead>
<!-- 게시글 목록 보여주는 ejs -->
<tbody>
<% for (i=0; i<list.length; i++) { %>
<tr>
<td><%=list[i].게시글ID%></td>
<td style="text-align:left"><%=list[i].제목%></td>
<td><%=list[i].작성일자%></td>
<td><%=list[i].작성자%></td>
</tr>
<% } %>
<tbody>
</table>
</div>
app.get('/products/:page', (req, res) => {
const page_size = 3; // 각 페이지의 최대 항목 수
const page = req.params.page || 1 // if page is null then 1, 현재 페이지 번호
console.log(page);
const sql = 'SELECT * FROM 게시글';
maria.query(sql, (err, rows, fields) => {
for(let i=0; i<rows.length; i++){
console.log('rows'+JSON.stringify(rows[i]));
rows[i].작성일자 = moment(rows[i].작성일자).format('YYYY-MM-DD');
}
console.log("rows: "+rows[1].date);
if (err) cosole.log('QUERY FAIL\n' + err);
else res.render('mainpage.ejs', {list:rows});
});
});
페이지네이션 구현에 대하여 이슈를 작성한다.
#3 이슈의 코드를 수정한다.
mainpage.ejs
<center>
<div class="page">
<ul class="page-item">
<li> <a href="#" class="num">1</a></li>
<li> <a href="#" class="num">2</a></li>
<li> <a href="#" class="num">3</a></li>
<li> <a href="#" class="num">4</a></li>
<li> <a href="#" class="num">5</a></li>
</ul>
</div>
</center>
게시글 상세 페이지를 구현한다.
SQL INSERT문을 실행하려고 할 때, 정의되지 않은 값을 사용한다는 다음 ERROR가 발생했다.
undefined
TypeError: Cannot read properties of undefined (reading 'username')
at /Users/ochaemin/workspace/cwnu-db-make-community/web/app.js:34:23
at Layer.handle [as handle_request] (/Users/ochaemin/workspace/cwnu-db-make-community/web/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/ochaemin/workspace/cwnu-db-make-community/web/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/Users/ochaemin/workspace/cwnu-db-make-community/web/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/Users/ochaemin/workspace/cwnu-db-make-community/web/node_modules/express/lib/router/layer.js:95:5)
at /Users/ochaemin/workspace/cwnu-db-make-community/web/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/Users/ochaemin/workspace/cwnu-db-make-community/web/node_modules/express/lib/router/index.js:346:12)
at next (/Users/ochaemin/workspace/cwnu-db-make-community/web/node_modules/express/lib/router/index.js:280:10)
at expressInit (/Users/ochaemin/workspace/cwnu-db-make-community/web/node_modules/express/lib/middleware/init.js:40:5)
at Layer.handle [as handle_request] (/Users/ochaemin/workspace/cwnu-db-make-community/web/node_modules/express/lib/router/layer.js:95:5)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.