(주) 망나니 힘집
[SpringBoot] reason: Incompatible parameter types in method reference expression 해결 Resolve 본문
스펙도 쌓니
[SpringBoot] reason: Incompatible parameter types in method reference expression 해결 Resolve
군포망나니 2025. 1. 28. 22:53

문제 상황
Article 목록을 뷰에다가 전달해주려는 그런 상황
문제 요약
@RequiredArgsConstructor
@Controller
public class BlogViewController {
private final BlogService blogService;
@GetMapping("/articles")
public String getArticls(Model model) {
List<ArticleListViewResponse> articles = blogService.findAll().stream()
.map(ArticleListViewResponse::new)
.toList();
model.addAttribute("articles", articles);
return "articleList";
}
}
@ Controller 소스코드임
저기서
.map(ArticleListViewResponse::new)
이 부분이 빨갛게 뜨길래 마우스를 올려다 보니까
문제 해결
@Getter
public class ArticleListViewResponse {
private final long id;
private final String title;
private final String content;
public ArticleListViewResponse(Long id ,String title, String content) {
this.id = id;
this.title = title;
this.content = content;
}
}
이게 문제임 지금 Response 에서 Long, String, String 즉 AllArgsment 를 하고 있는데
이게 아닌 객체를 넘겨야 했음 우린 생성하는 게 아니고 조회이니까...
문제 해결
@Getter
public class ArticleListViewResponse {
private final long id;
private final String title;
private final String content;
public ArticleListViewResponse(Article article) {
this.id = article.getId();
this.title = article.getTitle();
this.content = article.getContent();
}
}
'스펙도 쌓니' 카테고리의 다른 글
[클라우드] AWS 요금 $0.92 청구 분석 건 VPC? (0) | 2025.02.08 |
---|---|
[클라우드] 배포 실패 Log 분석 -> AWS 로그 파일 다운로드 먼저! (0) | 2025.02.08 |
Oh ... not-null property references a null or transient value 해결 Resolve (0) | 2025.01.28 |
H2 - Spring Boot Configuration (1) | 2025.01.28 |
테스트 코드는 무수한 반복 반복 반복 을 견뎌라!! (0) | 2025.01.27 |