简体   繁体   English

什么是 Querydsl PathBuilder 字符串参数“变量”用于

[英]What is Querydsl PathBuilder String parameter 'variable' used for

I'm working with Querydsl in my Spring Boot API for making some complex data filtering and when i declare the PathBuilder variable i've seen that first you have to pass statically your class like YourClass.class and then a string variable for the constructor as shown below: I'm working with Querydsl in my Spring Boot API for making some complex data filtering and when i declare the PathBuilder variable i've seen that first you have to pass statically your class like YourClass.class and then a string variable for the constructor as如下图:

    PathBuilder<Plan> entityPath = new PathBuilder<>(Plan.class, "plan");

So i was wondering why is necessary this string parameter and also why its name has to be the same as my class name, because when i delete it or modified it, the entityPath doesn't work.所以我想知道为什么需要这个字符串参数以及为什么它的名称必须与我的 class 名称相同,因为当我删除或修改它时, entityPath不起作用。

A PathExpression (which PathBuilder ) is by definition represents a path variable. PathExpressionPathBuilder )根据定义代表一个路径变量。 In your case, the path ending up in your query would be plan .在您的情况下,最终查询的路径将是plan Consecutively, you can build on to this path and create various path types.连续地,您可以在此路径上构建并创建各种路径类型。 For example property retrieval: entityPath.get("someProperty") will return a path expression that represents plan.somePropety .例如属性检索: entityPath.get("someProperty")将返回表示plan.somePropety的路径表达式。 So you can't create PathExpressions without an alias, because it would be essentially meaningless.所以你不能创建没有别名的PathExpressions ,因为它本质上是没有意义的。

Then why this alias is not always inferred from the Path types, well simply put: because it is not related.那么为什么这个别名并不总是从 Path 类型中推断出来,简单地说:因为它不相关。 The underlying entities used may have different naming strategies, you may want to mix up different path variables of the same type, you might reference a node that has a particular alias by itself.使用的底层实体可能有不同的命名策略,您可能想要混合相同类型的不同路径变量,您可能引用一个本身具有特定别名的节点。

The alias doesn't have to be equivalent to the simple classname, it has to be equivalent to the alias it references from any of the from/join clauses in the query.别名不必等同于简单的类名,它必须等同于它从查询中的任何 from/join 子句引用的别名。

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

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