티스토리 뷰
query method 사용시, projection 하기
무지성 dto 만들고, 무지성 query method 만들기
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Dto {
private String id;
}
List<Dto> findByOrderByIdDesc();
WARN [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver:207] Resolved [org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [kr.co.oti.pms.api.brd.notice.entity.Notice] to type [kr.co.oti.pms.api.brd.notice.service.BrdNoticeService$Dto]]
class가 아니고 interface로 하라는데?
public interface Dto {
String getId();
}
repository.findByOrderByIdDesc().stream().forEach(each -> {
log.debug("id: {}", each.getId());
});
List<Dto> findByOrderByIdDesc();
projection은 interface로.
'getId' 라는 method명은 Entity의 getter에 의해 정해진 method명으로 쓰는건줄 알았는데,
임의로 바꿔서 해보니 인식을 못함
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [....] on this ManagedType [......]
query method가 자동으로 field명을 인식하듯이 이거도 자동으로 인식하나봄.
'spring(boot)' 카테고리의 다른 글
[jpa]테이블 구조에 따라 Entity class (0) | 2023.11.07 |
---|---|
[jpa]@OneToOne (0) | 2023.11.04 |
[security]CORS preflight 요청 (0) | 2023.10.09 |
[jwt]구현 시, 고려할 점들 (0) | 2023.09.26 |
[security]JPA로 구현 시, Role table 없애기 (0) | 2023.09.08 |