Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Spring-Boot-Starter 에서 QueryDSL 사용을 위한 pom.xml 수정

No Formatexpand
titlepom.xml
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.9.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
.....................
<dependencies>
.....................
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-core</artifactId>
            <version>4.1.3</version>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
            <version>4.1.3</version>
        </dependency>
.....................
</dependencies>
.....................
	<build>
		<plugins>
            <!-- MUST add to use generate QueryDSL -->
            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>apt-maven-plugin</artifactId>
                <version>1.1.3</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <!-- Specifies the directory in which the query types are generated -->
                            <outputDirectory>target/generated-sources/querydsl</outputDirectory>
                            <!-- States that the APT code generator should look for JPA annotations -->
                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
	                <dependency>
			          <groupId>com.querydsl</groupId>
			          <artifactId>querydsl-apt</artifactId>
			          <version>4.1.3</version>
			      	</dependency>
		      	</dependencies>
            </plugin>


		</plugins>				
	</build>
.....................

...

유연하게 복합할수가 있습니다. 이것은 복합적인 검색인자값이 null 혹은 Optional 등을 포함하였을때

중첩 if문등을 억제할수가 있습니다.  예를들면, 기존 SQL개발 방식에서는 이름이 있냐? 없냐에 따라 SQL문이 분기처리가 되었고 두가지 구문을

관리하였을것입니다. 조건식이 복잡해질시.. 중첩 if문 처리가 더욱더 어려워지고  sql문은 typesafe하지 않기때문에

어떠한 케이스에서는 sql문 syntax 에러를 유발 하였습니다.


검색 SQL문을 생성할때, 검색조건이 없는경우(null) 다양한 SQL문을 CaseBy로 복합적으로 만들어야 했습니다.

  • Select * from address where name='민수1'
  • Select * from address
  • Select * from address where name='민수1' and addres like '%서%'


QueryDSL에서는 단지 필요한 조건만 동적으로 추가하기때문에 제어가 복잡해 지더라도가독성이 좋으며,

가독성및 사용성(인자값전달)이 편리해집니다.

TypeSafe하다란 말은 허용되지 않는 SQL문 수행을 빌드단계에서 걸러낼수가 있는 장점이 있습니다.

...