본문 바로가기
Node.js

[Node.js]쿼리 스트링 다루는 방법

by 반오십 코린이 2022. 10. 8.
728x90

localhost:3000/board/read/12 글 조회 페이지에서 

<form action="/board/update" method="get">
            <table border="1">
                <input type="hidden" name="idx" value="<%=row.idx%>"/>
                <tr>
                    <td>작성자</td>
                    <td><%=row.creator_id%></td>
                </tr>
                <tr>
                    <td>제목</td>
                    <td><%=row.title%></td>
                </tr>
                <tr>
                    <td>내용</td>
                    <td><%=row.content%></td>
                </tr>
                <tr>
                    <td>조회수</td>
                    <td><%=row.hit%></td>
                </tr>
                <tr>
                    <td>이미지</td>
                    <td><img src="/images/<%=row.img%>" width="500px" height="500px"></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <button type="submit">글 수정</button>
                        <a href="/board">리스트로 돌아가기</a>
                    </td>
                </tr>
        </table>
    </form>

해당 form tag에 input type hidden으로 name을 설정해주고 value 값을 지정해준 다음

글 수정 버튼을 눌러 get 방식으로 /board/update를 하면 이동한 url은

 

http://localhost:3000/board/update?idx=12

hidden 방식으로 넘겨준 idx의 값이 다음과 같이 들어가게 된다.

 

해당하는 updateController에서 다음과 같이 url을 require 하여 객체를 가져오고

다음과 같은 코드를 통해 쿼리스트링 사용 가능

728x90

'Node.js' 카테고리의 다른 글

[Node.js, 개인프로젝트] CRUD 기능 만들기 - GetList  (0) 2022.10.10
node js - Express.js  (1) 2022.09.20