강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của qwep0224
qwep0224

câu hỏi đã được viết

Trong thực tế! Truy vấn

Trực tiếp tạo lớp hỗ trợ Querydsl

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

Viết

·

303

0

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

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

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

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

 

 

 

javaJPA

Câu trả lời 3

0

yh님의 프로필 이미지
yh
Người chia sẻ kiến thức

안녕하세요. 박태규님

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

qwep0224님의 프로필 이미지
qwep0224
Người đặt câu hỏi

구글 공유 링크 남깁니다.

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

yh님의 프로필 이미지
yh
Người chia sẻ kiến thức

안녕하세요. 박태규님

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

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

https://bit.ly/3fX6ygx

 

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

 

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

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

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

감사합니다.

 

Hình ảnh hồ sơ của qwep0224
qwep0224

câu hỏi đã được viết

Đặt câu hỏi