일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- http
- transaction
- 스프링 핵심 기능
- 알고리즘
- 김영한
- Servlet
- QueryDSL
- JDBC
- db
- 스프링 핵심 원리
- 그리디
- Thymeleaf
- kotlin
- Greedy
- 자바
- pointcut
- SpringBoot
- Exception
- java
- AOP
- 백준
- Proxy
- Android
- JPQL
- spring
- jpa
- 스프링
- 인프런
- springdatajpa
- Spring Boot
- Today
- Total
목록projection (3)
개발자되기 프로젝트
1. @QueryProjetion DTO의 생성자에 @QUeryProjection 붙여주고 @Data public class MemberDto { private String username; private int age; @QueryProjection public MemberDto(String username, int age) { this.username = username; this.age = age; } public MemberDto() { } } compileQuerydsl을 실행하면 DTO로 Q파일로 만들어줌 ㄷㄷ /** * study.querydsl.dto.QMemberDto is a Querydsl Projection type for MemberDto */ @Generated("com.quer..
1. 프로젝션 : select의 대상을 지정. 2. 프로젝션 대상이 하나 인 경우 프로젝션 대상이 하나면 타입을 명확하게 지정할 수 있음 프로젝션 대상이 둘 이상이면 튜플이나 DTO로 조회 List result = queryFactory .select(member.username) .from(member) .fetch(); 2. 튜플 조회 프로젝션 대상이 둘 이상일 때 사용 com.querydsl.core.Tuple tuple.get(~)을 통해 데이터 꺼냄. tuple을 repository 계층 내부에서만 사용하고, 외부에는 DTO로 변환하여 내보내자 ㅋㅋ @Test public void tupleProjection(){ List result = queryFactory .select(member.use..
엔티티 대신에 DTO를 편리하게 조회할 때 사용 전체 엔티티가 아니라 딱 회원의 이름만 조회하고 싶은 경우! 1. closed Projection 인터페이스만 생성하면 구현체는 SpringDataJpa가 만듦. public interface UserNameOnly { String getUserName(); } 사용 방법 : 아래와 같이 return type으로 인터페이스를 지정해주면 됨. @Test public void projections(){ Team teamA = new Team("teamA"); em.persist(teamA); Member m1 = new Member("m1", 0, teamA); Member m2 = new Member("m2", 0, teamA); em.persist(m1);..