로그인

이소연's avatar
Aug 05, 2024
로그인
Contents
detail.js
이렇게 적으면 안돼
아웃터조인해야 함. 아니면 left join
왜냐면 이렇게 하면, 댓글 없는 게시글은 보이지 않으니까.
notion image
 

detail.js

import React from "react"; import { Button } from "react-bootstrap"; import { Link } from "react-router-dom"; const Detail = (props) => { function fetchDelete(postId) {} return ( <div> <Link to={"/updateForm/1"} className="btn btn-warning"> 수정 </Link> <Button className="btn btn-danger" onClick={() => fetchDelete(1)}> 삭제 </Button> <br /> <br /> <h1>제목1</h1> <hr /> <div>내용1</div> </div> ); }; export default Detail;
확인하면 이렇게 되어 잇음.
notion image
 
localhost:8080/api/boards/1/detail하면,
notion image
notion image
notion image
애는 오브젝트
 
 
notion image
notion image
pathvariable이런 식으로 받아왔었지!
notion image
input.js 찾아보삼. github에
notion image
notion image
notion image
notion image
notion image
notion image
notion image
jsx에 바인딩만 해둬라.
notion image
notion image
Detail.js
import axios from "axios"; import React, { useEffect, useState } from "react"; import { Button } from "react-bootstrap"; import { Link, useParams } from "react-router-dom"; const Detail = (props) => { const { id } = useParams(); const [post, setPost] = useState({ id: undefined, title: "", content: "", userId: undefined, username: "", owner: false, replies: [], }); useEffect(() => { console.log("postId", id); fetchDetail(id); }, []); async function fetchDetail(postId) { let response = await axios({ url: `http://localhost:8080/api/boards/${postId}/detail`, }); let responseBody = response.data; setPost(responseBody.body); } function fetchDelete(postId) {} return ( <div> <Link to={"/updateForm/1"} className="btn btn-warning"> 수정 </Link> <Button className="btn btn-danger" onClick={() => fetchDelete(post.id)}> 삭제 </Button> <br /> <br /> <h1>{post.title}</h1> <hr /> <div>{post.content}</div> </div> ); }; export default Detail;
notion image
4321 ⇒ 제목4321로 됨.-v
computer priperies?? 하려고
notion image
 
Share article

Coding's note