@DeleteMapping("/{id}")
public String deleteBook(
@PathVariable("id") Long id
) {
Book1 isRemoved = bookList.remove(id);
System.out.println(isRemoved);
// ! 에러 발생 부분
if (isRemoved == false) {
return "없는 책이라 못 지우는데요?";
} else {
return "이 책을 지웠어요 -" + id;
}
}
error: bad operand types for binary operator '=='
if (isRemoved == false) {
-> 잘못된 연산자 타입입니다.
-> 왼쪽과 오른쪽의 데이터 타입이 다르다.
const response = await fetch("/api/v1/boards/\${selectedId}", {
method: 'DELETE'
});


-> argument 입력 안 할 시 기본 설정 값
// ! 밑에 메소드에서 생성자에 '='id''은 뭐지???
async function fetchGetScores(sortType='id') {
const res = await fetch(API_URL + `?sort=\${sortType}`);
const data = await res.json(); // json 으로 받아온 내용을 객체로 변환환
console.log(data);
// 화면에 정보 렌더링
renderScoreList(data);
}
: (윗 코드) 아래와 같이 id, title, content, date를 필드로 갖는 BoardDetailDto을
(아래코드) 프론트에 ResponseEntity로 전달해주었는데,
(문제상황) 프론트에서 Fetch 해서 데이터를 받아오니 데이터가 비어 있음
public class BoardDetailDto {
private Long id; // 글번호
private String title; //제목
private String content; //내용
@JsonFormat(pattern="yyyy-MM-dd")
private LocalDateTime date; //작성일시
public BoardDetailDto(Board board) {
this.id = board.getId();
this.title = board.getTitle();
this.content = board.getContent();
this.date = board.getRegDateTime();
}
}
// ## 게시물 상세조회 ##
@GetMapping("/{id}")// "/api/v1/boards/{id}"
public ResponseEntity<?> findBoard(
@PathVariable Long id
) {
// 데이터베이스(Map)에서 해당 아이디를 가진 board 객체 가져오기
Board targetBoard = boardStore.get(id);
// 해당 id가 없는 경우, 없는 id 라고 메시지 보내기
if(targetBoard == null) {
return ResponseEntity
.status(404)
.body("없는 아이디입니다: id - " + id);
}
// 있는 아이디인 경우, BoardDetailDto로 변환해주기
BoardDetailDto boardDetailDto = new BoardDetailDto(targetBoard);
System.out.println(boardDetailDto);
return ResponseEntity
.ok()
.body(boardDetailDto);
}