如何解决Spring boot mapstruct 和modelMapper 比较混淆的问题
我有以下情况,我使用 spring 数据来获取实体列表, 并尝试使用 mapstruct 将这些实体映射到 DTO 列表,而不是使用 modelMapper 映射这些实体(我同时进行映射以分析缓慢问题)
public List<EntityADto> getListDto(String argument1,Integer argument2){
//bloc 1 : mapstruct mapping
List<EntityADto> result1=entityArepository.findAllByFilter( String argument1,Integer argument2).stream()
.map(entityA -> mapstructMapper.toDto(entityA ))
.collect(Collectors.toList());
//end bloc 1
//bloc 2 : modelMapper mapping
List<EntityADto> result2=entityArepository.findAllByFilter( String argument1,Integer argument2).stream()
.map(entityA -> modelMapper.map(entityA,EntityADto.class))
.collect(Collectors.toList());
//end bloc 2
}
我发现缓慢可能来自 FetchType,因为第一个执行的块确实很慢,但下一个会立即执行。例如,如果我将 bloc 2 放在 getListDTO 方法的顶部,然后将 bloc 1 放在下面,则 bloc 2 将运行得非常慢(大约 1 分钟),而 bloc 1 将运行得非常快(大约 0.1 秒)。
我尝试使用 FetchMode.JOIN 和 join fetch 来解决这个问题,但结果是一样的:
@Repository
@RepositoryRestResource(exported = false)
public interface EntityArepository extends JpaRepository< EntityA,Integer> {
@Fetch(FetchMode.JOIN)
@Query(" SELECT o FROM EntityA o " +
" and (o.propertyOne = :argument1)"+
" and (o.propertyTwo = :argument2 )"
)
List<EntityA> findAllByFilter(@Param("argument1") String argument1,@Param("argument2") Integer argument2 );
请问有什么建议吗?
提前致谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。