nextjs Data List
- NEXT.JS 기본개념
- NEXT.JS 설치
- NEXT.JS 실행방법
- NEXT.JS 파일 및 구조
- NEXT.JS 데이터 가져오기
- NEXT.JS API 쿼리데이터 생성
- NEXT.JS Components
- NEXT.JS page.js 파라미터 처리
- NEXT.JS app router 방식 client ip 주소 가져오는 방법
- NEXT.JS monaco-editor 사용방법
- NEXT.JS react-quill 사용방법
- NEXT.JS app router 방식 rss feed.xml 간단하게 설정 방법
- NEXT.JS app router 방식 sitemap.xml 간단하게 설정 방법
NEXT.JS API 쿼리데이터 생성
2023-11-14 00:00:00
/ 목차 /
- Next.JS API 쿼리데이터 생성
Next.JS API 쿼리데이터 생성
- DB데이터 쿼리 부분을 작성해서 execute('CALL Sp_Get_Data(?)', [Data]); 이부분에 넣어 주시면 됩니다. 이부분은 데이터가져오기에서 해당 파일 호출하시면 화면에 출력 됩니다.code import { getConnection } from '@/app/utils/db/dbconfig'; import { NextApiRequest, NextApiResponse } from 'next'; export default async function handler(req:NextApiRequest, res:NextApiResponse) { try { const { Data } = req.query; const conn = await getConnection(); // 쿼리 실행 const [DataResults] : any[] = await conn.execute('CALL Sp_Get_Data(?)', [Data]); // 연결 해제 conn.end(); const firstValues = DataResults[0]; res.status(200).json(firstValues); } catch (error) { console.error(error); res.status(500).json({ message: "Error Occurred" }); } };
Comment