2022. 2. 5. 17:26ใ๊ฐ๋ ์ ๋ฆฌ ์์ ์ค/๋ฌธ์ ์ ๋ฆฌ
๐ Code Content
Query dsl์ ์ฌ์ฉํ์ฌ ์ฃผ๋ํ๋์ด ๋ง๋ค ๊ฐ์กฑ ์ปค๋ฎค๋ํฐ ๊ฒ์ํ์ ๋ชฉ๋ก ์กฐํ๋ฅผ ๊ตฌํํ๋ ค๊ณ ํ๋ ๊ฒ์ด์์.
"์ด ํฌ์คํ ์ ์ฟ ํก ํํธ๋์ค ํ๋์ ์ผํ์ผ๋ก, ์ด์ ๋ฐ๋ฅธ ์ผ์ ์ก์ ์์๋ฃ๋ฅผ ์ ๊ณต๋ฐ์ต๋๋ค."
๐ฝ SystemManualQueryRepository
package com.hongga.repository.querydsl.system_manual;
import com.hongga.dto.SystemManualResponseDTO;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import java.util.List;
import static com.hongga.entity.system_manual.QSystemManual.systemManual;
/**
* ์์คํ
๋ฉ๋ด์ผ DB Query ์์
์ ์ํ Querydsl Repository
* <pre>
* <b>History:</b>
* ์ฃผ๋ํ๋, 1.0, 2022.02.05 ์ต์ด ์์ฑ
* </pre>
*
* @author ์ฃผ๋ํ๋
* @version 1.0, 2022.02.05 ์ต์ด ์์ฑ
* @See "Not thing"
* @see <a href=""></a>
*/
@RequiredArgsConstructor @Slf4j
@Repository public class SystemManualQueryRepository {
private final JPAQueryFactory jpaQueryFactory;
private final EntityManager entityManager;
// ์ ์ฒด(๋ชฉ๋ก) ์กฐํ
public Page<SystemManualResponseDTO> systemManualFindAll(Pageable pageable) { // ํ์ด์ง ์ฒ๋ฆฌ
log.info("SystemManualQueryRepository๊ฐ ๋์ํ์์ต๋๋ค!");
log.info("systemManualFindAll(Pageable pageable, Long memberId)์ด ๋์ํ์์ต๋๋ค!");
List<SystemManualResponseDTO> systemManualDTOList = jpaQueryFactory
.select(Projections.constructor(SystemManualResponseDTO.class,
systemManual.systemManualId.as("systemManualId"),
systemManual.writer.nickName.as("memberNickname"),
systemManual.title.as("title"),
systemManual.registerDate.as("registerDate"),
systemManual.modifyDate.as("modifyDate")))
.from(systemManual)
.innerJoin(systemManual.writer)
.orderBy(systemManual.systemManualId.desc())
.fetch();
log.info("List<SystemManualResponseDTO> systemManualDTOList = jpaQueryFactory.select๊ฐ ๋์ ์๋ฃ ๋์์ต๋๋ค!");
log.info("ํ์ด์ง ์ฒ๋ฆฌ๋ฅผ ์์ํฉ๋๋ค!");
int start = (int)pageable.getOffset();
int end = Math.min((start + pageable.getPageSize()), systemManualDTOList.size());
log.info("ํ์ด์ง ์ฒ๋ฆฌ๊ฐ ์๋ฃ ๋์์ต๋๋ค!");
return new PageImpl<>(systemManualDTOList.subList(start, end), pageable, systemManualDTOList.size());
} // systemManualFindAll(Pageable pageable) ๋
} // class ๋
๐ฝ SystemManualResponseDTO
package com.hongga.dto;
import lombok.*;
import java.time.LocalDateTime;
/**
* System Manual ์๋ต์ ์ํ DTO
* <pre>
* <b>History:</b>
* ์ฃผ๋ํ๋, 1.0, 2022.02.05 ์ต์ด ์์ฑ
* </pre>
*
* @author ์ฃผ๋ํ๋
* @version 1.0, 2022.02.05 ์ต์ด ์์ฑ
* @See "์ฝ๋๋ก ๋ฐฐ์ฐ๋ ์คํ๋ง ๋ถํธ ์น ํ๋ก์ ํธ"
* @see <a href=""></a>
*/
@Getter @NoArgsConstructor @AllArgsConstructor @Builder
public class SystemManualResponseDTO {
private Long systemManualId; // ๊ฒ์๊ธ ๋ฒํธ
private String memberNickname; // ์์ฑ์ ๋๋ค์
private String title; // ๊ธ ์ ๋ชฉ
private LocalDateTime registerDate, modifyDate; // ๊ฒ์๊ธ ๋ฑ๋ก / ์์ ์ผ
private Long writerId; // ์์ฑ์ ๊ณ ์ ๋ฒํธ
} // class ๋
โ ๏ธ ๋ฌธ์ ๋ฐ์!
2022-02-05 17:06:15.829 ERROR 7519 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.querydsl.core.types.ExpressionException: No constructor found for class com.hongga.dto.SystemManualResponseDTO with parameters: [class java.lang.Long, class java.lang.String, class java.lang.String, class java.time.LocalDateTime, class java.time.LocalDateTime]] with root cause
com.querydsl.core.types.ExpressionException: No constructor found for class com.hongga.dto.SystemManualResponseDTO with parameters: [class java.lang.Long, class java.lang.String, class java.lang.String, class java.time.LocalDateTime, class java.time.LocalDateTime]
at com.querydsl.core.util.ConstructorUtils.getConstructorParameters(ConstructorUtils.java:121) ~[querydsl-core-5.0.0.jar:na]
at com.querydsl.core.types.ConstructorExpression.<init>(ConstructorExpression.java:84) ~[querydsl-core-5.0.0.jar:na]
at com.querydsl.core.types.ConstructorExpression.<init>(ConstructorExpression.java:74) ~[querydsl-core-5.0.0.jar:na]
at com.querydsl.core.types.Projections.constructor(Projections.java:121) ~[querydsl-core-5.0.0.jar:na]
at com.hongga.repository.querydsl.system_manual.SystemManualQueryRepository.systemManualFindAll(SystemManualQueryRepository.java:44) ~[classes/:na]
at com.hongga.repository.querydsl.system_manual.SystemManualQueryRepository$$FastClassBySpringCGLIB$$9e2c3609.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.15.jar:5.3.15]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:783) ~[spring-aop-5.3.15.jar:5.3.15]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.15.jar:5.3.15]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753) ~[spring-aop-5.3.15.jar:5.3.15]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-5.3.15.jar:5.3.15]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.15.jar:5.3.15]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753) ~[spring-aop-5.3.15.jar:5.3.15]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698) ~[spring-aop-5.3.15.jar:5.3.15]
at com.hongga.repository.querydsl.system_manual.SystemManualQueryRepository$$EnhancerBySpringCGLIB$$5cf2a422.systemManualFindAll(<generated>) ~[classes/:na]
at com.hongga.service.SystemManualServiceImpl.systemManualList(SystemManualServiceImpl.java:119) ~[classes/:na]
at com.hongga.controller.system_manual.SystemManualController.systemManualList(SystemManualController.java:87) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.15.jar:5.3.15]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.15.jar:5.3.15]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.15.jar:5.3.15]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.15.jar:5.3.15]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.15.jar:5.3.15]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.15.jar:5.3.15]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.15.jar:5.3.15]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.15.jar:5.3.15]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.15.jar:5.3.15]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.15.jar:5.3.15]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) ~[tomcat-embed-core-9.0.56.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.15.jar:5.3.15]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.56.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.56.jar:9.0.56]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:122) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:116) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:109) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter.doFilterInternal(DefaultLogoutPageGeneratingFilter.java:58) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.15.jar:5.3.15]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:237) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:223) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:219) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:213) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.15.jar:5.3.15]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:110) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.15.jar:5.3.15]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183) ~[spring-security-web-5.6.1.jar:5.6.1]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354) ~[spring-web-5.3.15.jar:5.3.15]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267) ~[spring-web-5.3.15.jar:5.3.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.15.jar:5.3.15]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.15.jar:5.3.15]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1732) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.56.jar:9.0.56]
at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]
๐ค ๋ฌด์์ ํ๋ ค๊ณ ํ์๋๊ฐ?
์ฃผ๋ํ๋์ ์์ ๊ฐ์ด Postman์ ์ด์ฉํ์ฌ ์ฃผ๋ํ๋์ด ๋ง๋ ๊ฒ์ํ์ ๋ชฉ๋ก์ ๋ชจ๋ ๊ฐ์ ธ์ฌ ์ ์๋ API๋ฅผ ํธ์ถํ ๊ฒ์ด์์.
๊ทธ๋ฐ๋ฐ, 500 Error๊ฐ ๋ฐํ์ด ๋์๊ณ , ์์ ๊ฐ์ด ์์ฑ์ ๊ด๋ จ ์์ธ๊ฐ ๋ฐ์ํ ๊ฒ์ด์์.
๐ค ์์ธ ๋ถ์
์์ ๋ฌธ์ ๋ ๋ฐ๋ก Query dsl์ Respository์ DTO์ ํ๋๊ฐ ์ ํํ๊ฒ ์ผ์นํด์ผ ํ๋๋ฐ ์ผ์นํ์ง ์์์ ๋ฐ์ํ๋ ๋ฌธ์ ์ธ ๊ฒ์ด์์.
DTO ํ๋์๋ writerId๋ผ๋ ํ๋๊ฐ ์์ง๋ง ์ด๊ฒ์ Repository์์๋ ์ฒ๋ฆฌ๋ฅผ ํด ์ฃผ์ง ์์ ๊ฒ์ด ๋ฌธ์ ๊ฐ ๋ ๊ฒ์ด์์.
๐ป ๋ฌธ์ ํด๊ฒฐ!
DTO์ writerId๋ผ๋ ํ๋๋ฅผ ์์ ๊ณ , ๋ค์ API๋ฅผ ํธ์ถํด ๋ณด๋ฉด ๋ฌธ์ ๋ ํด๊ฒฐ ๋๋ ๊ฒ์ด์์.
๐ก ์ฐธ๊ณ ์๋ฃ
DTO์์ ์ ์ํ๋ ํ๋์ Repository์์ select๋ก ํํํ๊ณ ์ ํ๋ ํ๋๊ฐ ์์ ํ ์ผ์นํด์ผ ํ๋ ๊ฒ์ด Query dsl์ ์ฌ์ฉํ ๋ ๊ด๊ฑด์ด๋ค.
1. ๋ชจ๋ ํ๋์ ํ์ ์ด ์ผ์นํด์ผ ํ๋ค.
2. ๋ชจ๋ ํ๋์ ์์๊ฐ ์ผ์นํด์ผ ํ๋ค.
3. Repository(Query dsl์ฉ) ์ชฝ์์์ ํ๋๋ช ๊ณผ DTO ์ชฝ์์์ ํ๋๋ช ์ด ์ ํํ ์ผ์นํด์ผ ํ๋ค. ๋ง์ฝ ๋ค๋ฅด๋ค๋ฉด ์์ 'SystemManualQueryRepository.class' ์ฒ๋ผ .as(๋ณ์นญ) Method๋ฅผ ํตํด DTO ์ชฝ์์์ ํ๋๋ช ๊ณผ ๊ฐ๋๋ก ๋ณ์นญ์ ์ง์ ํด ์ค๋ค.
"์ด ํฌ์คํ ์ ์ฟ ํก ํํธ๋์ค ํ๋์ ์ผํ์ผ๋ก, ์ด์ ๋ฐ๋ฅธ ์ผ์ ์ก์ ์์๋ฃ๋ฅผ ์ ๊ณต๋ฐ์ต๋๋ค."