JPA 방언 설정
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB106Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.show_sql=true
faq 게시판 crud 수정, css, 게시판 역순정렬
questionId가 undefined로 전달되는 문제 :
fetchQuestions() {
axios.get(`http://localhost:3000/api/faqquestions/paged?page=${this.currentPage}&size=${this.pageSize}`)
.then(response => {
console.log('Response data:', response.data);
console.log('Questions array:', response.data.questions);
// 받아온 데이터를 처리하여 적절히 출력
this.questions = response.data.questions.map((question, index) => ({
id: question.question_id,
title: question.title,
writer: question.writer,
date: new Date(question.date).toLocaleDateString('ko-KR', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
}),
number: response.data.totalElements - (this.currentPage * this.pageSize) - index
}));
해결 >
id: question.question_id를 id: question.id 로 수정.
<tr v-for="(question, index) in questions" :key="question.id" @click="goToDetail(question.id, index)">
1. 서버 응답 데이터 구조:
서버에서 반환하는 데이터 구조에서 질문의 고유 식별자로 question_id 속성을 사용하고 있었습니다. 하지만 클라이언트 측에서는 id 속성을 사용하여 질문을 식별하고 있었습니다.
2. 클라이언트 측 questions 배열 초기화:
fetchQuestions 메서드에서 questions 배열을 초기화할 때, 서버 응답 데이터의 question_id 속성을 id로 매핑하지 않고 있었습니
다. 이로 인해 questions 배열의 각 객체에는 id 속성이 존재하지 않았습니다.
3. @click 이벤트 핸들러에서 question.id 사용:
<tr> 태그의 @click 이벤트 핸들러에서 goToDetail(question.id)로 question.id를 전달하고 있었습니다. 하지만 questions 배열의 각 객체에는 id 속성이 존재하지 않았기 때문에 question.id는 undefined로 평가되었습니다.
4. goToDetail 메서드에 questionId 값 사용:
goToDetail 메서드에서는 전달받은 questionId 값을 사용하여 해당 질문의 상세 페이지로 이동하고 있었습니다. 하지만 questionId가 undefined로 전달되었기 때문에 상세 페이지로 이동할 수 없었습니다.
따라서 id: question.question_id를 id: question.id로 수정함으로써 다음과 같은 변화가 생겼습니다:
- questions 배열 초기화 시 서버 응답 데이터의 question_id 속성을 id로 매핑하게 되었습니다.
- questions 배열의 각 객체에는 id 속성이 존재하게 되었습니다.
- @click 이벤트 핸들러에서 question.id를 전달할 때 올바른 값이 전달되게 되었습니다.
- goToDetail 메서드에서 전달받은 questionId 값이 undefined가 아닌 실제 질문의 고유 식별자 값이 되었습니다.
1. 내가 원하는건 글쓰기 버튼은 관리자에게만 보이기.
2. 작성된 글은 리스트로 출력되고, 글 제목을 누르면 다음 페이지로 넘어가는 것이 아니라 토글 형식으로 열려서 내용이 보임.
- 문제 : db의 글을 다 삭제하고 새로 썼더니 내용 출력이 되지 않음.
- 원인 : db의 글과 게시판의 글 번호가 달라서임.
- 해결 : faq_del이 1인 삭제된 글은 find하지 않게 함. (FaqQuestionService에서)
데이터베이스에 글이 등록되면 기본으로 faq_del이 0으로 들어간다.
public Page<FaqQuestion> getQuestionsPaged(Pageable pageable) {
// findAll()이 아니라, faq_del이 0인 글만 조회
return faqQuestionRepository.findByFaqdel(0, pageable);
}
'프로젝트' 카테고리의 다른 글
[Spring] 글쓰기 제한하기 관리자만 글 등록 가능하게 하기 (0) | 2024.05.27 |
---|---|
[Spring boot, Vue3] 사이트 크롤링 하기 (0) | 2024.05.27 |
마이페이지에 DB값 불러와서 출력하기 (0) | 2024.05.20 |
DB에 있는 List값을 불러오지 못하는 경우 (0) | 2024.05.20 |
기존 DB 테이블에 id 저장하기 (토큰으로 받아오기) (0) | 2024.05.20 |
댓글