[英]How to Convert JpaRepository result to my custom DTO class
我想将页面转换为页面
所以我是这样实现的
@GetMapping("/history")
public Page<ResponseAllHistoryDto> getAllHistory() {
Pageable pageable = PageRequest.of(0, 20, Sort.by("createdAt"));
Page<History> histories = historyRepository.findAll(pageable);
return histories.map(history -> {
return ResponseAllHistoryDto.builder()
.history(history)
.tags(tagRepository.findByHistoryHistoryId(history.getHistoryId()))
.auths(authRepository.findByHistoryHistoryId(history.getHistoryId()))
.build();
});
}
可悲。 它给我
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.wrapsody.demo.ResponseAllHistoryDto and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.data.domain.PageImpl["content"]->java.util.Collections$UnmodifiableRandomAccessList[0])
问题是什么....:(
您的DTO
类需要有一个默认的构造函数、getter 和 setter。 尝试使用 lombok 的@Data
对其进行注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.