简体   繁体   English

QueryDsl MongoDB - 访问深度嵌套的 Object 以进行查询

[英]QueryDsl MongoDB - Accessing Deeply Nested Object for Query

I have issues trying to access nested object when using BooleanBuilder .我在使用BooleanBuilder时尝试访问嵌套的 object 时遇到问题。 I have read that the default is 2 levels, but for my use case, I need to access 3rd level nested objects.我读过默认值为 2 级,但对于我的用例,我需要访问第 3 级嵌套对象。 So I have added @QueryInit as pointed out in many other answers.所以我添加了@QueryInit ,正如许多其他答案中所指出的那样。 But I still cannot access it.但我仍然无法访问它。 Here is my code:这是我的代码:

@Document
public class Order implements Serializable {

     @QueryInit(*.*)
     private Item item;

}

public class Item implements Serializable {
   private Details details;
}

public class Details implements Serializable {
   private String name;
}

public static BooleanExpression name(String name) {
  QOrder order = QOrder.order;
  return order.item.details.name.eq(name)
}

I have QOrder , QItem classes generated and working fine.我生成了QOrderQItem类并且工作正常。 But details.description gives error because QDetails class was not generated.但是 details.description 给出了错误,因为没有生成QDetails class。 How do I make it generate QDetails ?如何让它生成QDetails

The first problem I see is that you missed a semicolon on the return statement which might be causing you some other issues.我看到的第一个问题是您在 return 语句中遗漏了一个分号,这可能会导致您出现一些其他问题。 The way to generate QDetails is to first reference the query, and request the details from the assigned result.生成QDetails的方式是首先引用查询,然后从分配的结果中请求详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM