BoardDetailForm.module.css
.detail-container {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
width: 100%;
}
.detail-title {
font-size: 28px;
font-weight: bold;
margin-bottom: 20px;
text-align: center;
}
.detail-info {
display: flex;
justify-content: space-between;
width: 100%;
max-width: 800px;
margin-bottom: 20px;
}
.detail-author,
.detail-date,
.detail-hit {
font-size: 14px;
color: gray;
}
.detail-content {
width: 100%;
max-width: 800px;
border: 1px solid #ddd;
padding: 15px;
background-color: #fafafa;
border-radius: 5px;
box-shadow: 0px 4px 10px rgba(82, 80, 80, 0.1);
}
.detail-content:hover {
background-color: #f9f9f9;
}
.detail-info p {
margin: 0;
padding: 5px;
}
.button-container {
display: flex;
justify-content: space-between;
width: 30%;
max-width: 800px;
}
.board-write-button {
flex: 1;
padding: 10px;
border-radius: 4px;
border: none;
background-color: #FFDFF6;
color: black;
font-weight: bold;
cursor: pointer;
margin: 10px 10px;
}
.board-write-button:hover {
background-color: #f5b7e3;
}
BoardDetailForm.jsx
import React, { useEffect, useState } from 'react';
import axios from 'axios';
import styles from '../../css/BoardDetailForm.module.css';
import { useNavigate, useParams } from 'react-router-dom';
const BoardDetailForm = () => {
const { seq } = useParams();
const [dto, setDto] = useState({});
const navigate = useNavigate();
useEffect(() => {
axios.get(`http://localhost:8080/spring/board/detail?seq=${seq}`)
.then(res => {
console.log('게시글 데이터:', res.data);
setDto(res.data);
})
.catch(error => console.error('에러:', error));
}, [seq]);
return (
<div className={styles['detail-container']}>
<h2 className={styles['detail-title']}>{dto.subject}</h2>
<div className={styles['detail-info']}>
<p className={styles['detail-author']}>작성자: {dto.name}</p>
<p className={styles['detail-date']}>{new Date(dto.logtime).toLocaleDateString()}</p>
<p className={styles['detail-hit']}>조회수: {dto.hit}</p>
</div>
<div className={styles['detail-content']}>
<p>{dto.content}</p>
</div>
<div className={styles['button-container']}>
<button className={styles['board-write-button']} onClick={() => navigate('/board/boardListForm')}>글목록</button>
<button className={styles['board-write-button']} >수정</button>
<button className={styles['board-write-button']} >삭제</button>
</div>
</div>
);
};
export default BoardDetailForm;
BoardController.java
@GetMapping(value = "detail")
public BoardDTO detail(@RequestParam int seq) {
System.out.println("seq = " + seq);
BoardDTO boardDTO = boardService.getDetail(seq);
return boardDTO;
}
BoardService.java
package board.service;
import java.util.List;
import board.bean.BoardDTO;
public interface BoardService {
public void write(String subject, String content);
public List<BoardDTO> getList();
public BoardDTO getDetail(int seq);
}
BoardServiceImpl.java
@Override
public BoardDTO getDetail(int seq) {
BoardDTO boardDTO = boardDAO.getDetail(seq);
System.out.println("boardDTO = " + boardDTO);
return boardDTO;
}
BoardDAO.java
package board.dao;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import board.bean.BoardDTO;
@Mapper
public interface BoardDAO {
public int write(Map<String, String> map);
public void refUpdate();
public List<BoardDTO> getList();
public BoardDTO getDetail(int seq);
}
boardMapper.xml
<select id="getDetail" parameterType="int" resultType="boardDTO">
select * from board where seq = #{seq}
</select>
BoardController.java
@GetMapping(value = "detail")
public BoardDTO detail(@RequestParam int seq) {
System.out.println("seq = " + seq);
BoardDTO boardDTO = boardService.getDetail(seq);
return boardDTO;
}
BoardDetailForm.jsx
useEffect(() => {
axios.get(`http://localhost:8080/spring/board/detail?seq=${seq}`)
.then(res => {
console.log('게시글 데이터:', res.data);
setDto(res.data);
})
.catch(error => console.error('에러:', error));
}, [seq]);
return (
<div className={styles['detail-container']}>
<h2 className={styles['detail-title']}>{dto.subject}</h2>
<div className={styles['detail-info']}>
<p className={styles['detail-author']}>작성자: {dto.name}</p>
<p className={styles['detail-date']}>{new Date(dto.logtime).toLocaleDateString()}</p>
<p className={styles['detail-hit']}>조회수: {dto.hit}</p>
</div>
<div className={styles['detail-content']}>
<p>{dto.content}</p>
</div>
<div className={styles['button-container']}>
<button className={styles['board-write-button']} onClick={() => navigate('/board/boardListForm')}>글목록</button>
<button className={styles['board-write-button']} >수정</button>
<button className={styles['board-write-button']} >삭제</button>
</div>
</div>
);
'REACT' 카테고리의 다른 글
DAY 82 - React - Context / 마지막 실습(HOMEWORK) (2024.11.01) (2024.11.04) (1) | 2024.11.02 |
---|---|
DAY 81 - React - Redux (2024.10.31) (0) | 2024.10.31 |
DAY 79, 80 - Spring + React +MyBatis(MySQL) HOMEWORK - 글쓰기 / 글목록 (2024.10.29) (2024.10.30) (0) | 2024.10.30 |
DAY 79 - Spring + React +MyBatis(MySQL) (2024.10.29) (0) | 2024.10.30 |
DAY 78 - React HOMEWORK (2024.10.28) (0) | 2024.10.28 |