0
使用Spring Data MongoDB。而且我已經定義我的MongoRepository此查詢:如何將數組傳遞給MongoRepository @Query?
@Query("{'type':?0, 'tags.type':?1, 'tags.softSkill.name': {$all: ?2}}")
List<Foo> findByTypeAndTags_TypeAndTags_SoftSkills(
FooType type, TagType tagType, String[] softSkills);
當我想用$all
操作,我不能通過構建方法命名方式查詢,所以我使用@Query
註解。
問題是,它不喜歡String[]
,我試圖通過?2
參數。我嘗試了一個列表,但錯誤依然存在。
value expected to be of type java.util.List but is class java.lang.String toString:fooStr
在一個蒙戈殼會是這樣:$all: ['foo1','foo2']
富抽象的實體是這樣的:
@Data
@Document(collection="foes")
public abstract class Foo {
/*...*/
protected List<Tag> tags = new ArrayList<>();
}
標籤 asbtract POJO:
@Data
public abstract class Tag {
protected final TagType type;
protected TagLevel level;
}
TagSoftSkill POJO:
@Data
@EqualsAndHashCode(callSuper=true)
public class TagSoftSkill extends Tag{
private SoftSkill softSkill; //another pojo that has a "name" field
public TagSoftSkill() {
super(TagType.SOFT_SKILL);
}
}
我已經調試和softSkills
打印[foo]
。我修改的值是['foo']
,但沒有變化。
你能告訴我們輸入參數arg'softSkills'失敗的示例調用方法嗎?請將你的'Foo' bean添加到帖子中? – Veeram
@Veeram ok,done – anat0lius
我不能重新創建錯誤。在1.10.4 spring mongo發行版中,列表和數組都適用於我。你能爲異常添加堆棧跟蹤嗎? – Veeram