Skip to content

Commit ad3143b

Browse files
committed
복습
1 parent db272be commit ad3143b

File tree

29 files changed

+51
-1
lines changed

29 files changed

+51
-1
lines changed

.DS_Store

-8 KB
Binary file not shown.

JPA/.DS_Store

-6 KB
Binary file not shown.

login/.DS_Store

-6 KB
Binary file not shown.

login/src/.DS_Store

-6 KB
Binary file not shown.

login/src/main/.DS_Store

-6 KB
Binary file not shown.

login/src/main/java/.DS_Store

-6 KB
Binary file not shown.

login/src/main/java/hello/.DS_Store

-6 KB
Binary file not shown.
-6 KB
Binary file not shown.
Binary file not shown.
-6 KB
Binary file not shown.

message/.DS_Store

-6 KB
Binary file not shown.

message/src/.DS_Store

-6 KB
Binary file not shown.

message/src/main/.DS_Store

-6 KB
Binary file not shown.

message/src/main/java/.DS_Store

-6 KB
Binary file not shown.

message/src/main/java/hello/.DS_Store

-6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

querydsl/src/main/java/study/querydsl/entity/Member.java

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class Member {
2626
@JoinColumn(name = "team_id")
2727
private Team team;
2828

29+
30+
2931
public Member(String username) {
3032
this(username, 0);
3133
}

querydsl/src/main/resources/application.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ spring:
1515
jooq:
1616
sql-dialect: org.hibernate.dialect.MySQL8Dialect
1717

18+
1819
logging.level:
1920
org.hibernate.SQL: debug

querydsl/src/test/java/study/querydsl/QuerydslBasicTest.java

+48-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
import com.querydsl.core.types.Projections;
1010
import com.querydsl.core.types.dsl.BooleanExpression;
1111
import com.querydsl.core.types.dsl.Expressions;
12+
import com.querydsl.core.types.dsl.NumberPath;
13+
import com.querydsl.core.types.dsl.StringPath;
1214
import com.querydsl.jpa.JPAExpressions;
1315
import com.querydsl.jpa.impl.JPAQuery;
1416
import com.querydsl.jpa.impl.JPAQueryFactory;
1517
import org.junit.jupiter.api.BeforeEach;
1618
import org.junit.jupiter.api.Test;
1719
import org.springframework.beans.factory.annotation.Autowired;
1820
import org.springframework.boot.test.context.SpringBootTest;
21+
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
1922
import org.springframework.test.annotation.Commit;
2023
import org.springframework.transaction.annotation.Transactional;
2124
import study.querydsl.dto.MemberDto;
@@ -695,7 +698,7 @@ public void sqlFunction() {
695698
}
696699
}
697700

698-
// 소문자 함수
701+
// 소문자 함.
699702
@Test
700703
public void sqlFunction2() {
701704
List<String> result = jpaQueryFactory
@@ -710,6 +713,50 @@ public void sqlFunction2() {
710713
}
711714
}
712715

716+
@Test
717+
public void practiceV1() {
718+
String username = "member1";
719+
Integer age = null;
720+
721+
//동적 쿼리
722+
List<Member> result = jpaQueryFactory
723+
.selectFrom(member)
724+
.where(allEq(username, age))
725+
.fetch();
726+
727+
}
728+
729+
private BooleanExpression usernameEqV2(String username) {
730+
return username != null? member.username.eq(username) : null;
731+
}
732+
733+
private BooleanExpression ageEqV2(Integer age) {
734+
return age != null? member.age.eq(age) : null;
735+
}
736+
737+
private Predicate allEqV2(String usernameCond, Integer ageCond) {
738+
return usernameEq(usernameCond).and(ageEq(ageCond));
739+
}
740+
741+
@Test
742+
public void practiceV2() {
743+
long updateCount = jpaQueryFactory
744+
.update(member)
745+
.set(member.username, "memberA")
746+
.where(member.username.eq("member1"))
747+
.execute();
748+
749+
assertThat(updateCount).isEqualTo(1);
750+
751+
long deleteCount = jpaQueryFactory
752+
.delete(member)
753+
.where(member.username.eq("member1"))
754+
.execute();
755+
756+
assertThat(deleteCount).isEqualTo(1);
757+
758+
759+
}
713760

714761

715762
}

validation/.DS_Store

-6 KB
Binary file not shown.

validation/src/.DS_Store

-6 KB
Binary file not shown.

validation/src/main/.DS_Store

-6 KB
Binary file not shown.

validation/src/main/java/.DS_Store

-6 KB
Binary file not shown.
-6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)