• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

쿼리 데이터 조회가 안됩니다 ㅠㅠ..

22.06.29 20:12 작성 조회수 188

0

비슷한 예제로 계시판을 하나 만들었는데, 

콘솔에 나온 쿼리로 db에 쿼리 조회를 하면 조회가 되는데

콘솔에서는 값이 null이라고 나오네요 ㅠㅠ..

뭔지 모르겠습니다 ㅠㅠ..

 

 

 

답변 3

·

답변을 작성해보세요.

0

안녕하세요. 박태규님

2가지 문제가 있습니다.

문제1

문제가 있는 코드

pictureService를 의존관계 주입받지 않습니다. 따라서 null 예외가 발생합니다.

public class PostRepositoryImpl implements PostRepositoryCustom{

private final JPAQueryFactory queryFactory;
public PostRepositoryImpl(EntityManager em){
this.queryFactory = new JPAQueryFactory(em);
}

public PictureService pictureService;

해결 코드

public class PostRepositoryImpl implements PostRepositoryCustom{

private final JPAQueryFactory queryFactory;
private final PictureService pictureService;

public PostRepositoryImpl(EntityManager em, PictureService pictureService){
this.queryFactory = new JPAQueryFactory(em);
this.pictureService = pictureService;
}

 

문제2

문제가 있는 코드

코드를 보시면 postId가 자기 자신을 입력하고 있습니다. 파라미터로 넘어오는 PostId는 대문자 입니다.

@QueryProjection
public PostListDto(Long memberId, Long PostId, String title){
this.memberId = memberId;
this.postId = postId;
this.title = title;
}

 

해결 코드

    @QueryProjection
public PostListDto(Long memberId, Long PostId, String title){
this.memberId = memberId;
// this.postId = postId;
this.postId = PostId;
this.title = title;
}

 

감사합니다.

0

박태규님의 프로필

박태규

질문자

2022.07.05

구글 공유 링크 남깁니다.

https://drive.google.com/file/d/1uRcFTFIRd3F5WrPSvMeYROv9THEBtQyI/view?usp=sharing

 

>> 방법 입니다.

 

1. member insert  - 하단의 url로 post날립니다.

post : http://localhost:8080/api/member/join

{
"name" : "홍길동",
"telNum" : "44445555",
"loginFlag" : "new"
}
 
 
2. 글 insert 
http://localhost:8080/ 으로 들어가서
memberId : 1
제목 : 아무거나~~
파일등록 : 이미지 파일을 하나 선택
 
하여 저장합니다.
 
3.get 으로 http://localhost:8080/api/post/postList?page=0&size=5
 
를 사용하면 문의내용이 전시됩니다.

0

안녕하세요. 박태규님

전체 프로젝트를 압축해서 구글 드라이브로 공유해서 링크를 남겨주세요.

구글 드라이브 업로드 방법은 다음을 참고해주세요.

https://bit.ly/3fX6ygx

 

주의: 업로드시 링크에 있는 권한 문제 꼭 확인해주세요

 

추가로 다음 내용도 코멘트 부탁드립니다.

1. 실행 방법을 알려주세요.

2. 어떻게 문제를 확인할 수 있는지 자세한 설명을 남겨주세요.

감사합니다.