gpt4 book ai didi

java - Spring data mongodb repository findAll字段排除

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:22:19 24 4
gpt4 key购买 nike

我有一个关于 spring data mongodb 存储库的奇怪问题。我想从我的 findAll 请求中排除一个字段。我怎样才能做到这一点?

这非常有效:

@Query(fields = "{'objectContentAsJson':0}")
Page<ObjectHistory> findByObjectIdAndServiceIgnoreCase( String objectId, String service, Pageable pageable );

但是 findAll 没有机会:

@Query(fields = "{'objectContentAsJson':0}")
Page<ObjectHistory> findAll( Pageable pageable );

抛出:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type ObjectHistory! at org.springframework.data.mapping.PropertyPath.(PropertyPath.java:75) at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270) at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241) at org.springframework.data.repository.query.parser.Part.(Part.java:76)

最佳答案

添加一个空的过滤条件将为您解决问题:

@Query(value = "{}", fields = "{'objectContentAsJson':0}")
Page<ObjectHistory> findAll(Pageable pageable);

显然,当您没有指定value 参数来过滤结果时,Spring Data 会尝试从方法名称派生查询,但不知何故,无法识别findAll< 的特殊含义.

关于java - Spring data mongodb repository findAll字段排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35334036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com