org.springframework.data.repository.query.parser.Part的用途是什么?

时间:2018-07-31 08:02:35

标签: spring-boot jpa spring-data-jpa spring-data jpa-2.0

正如您在标题中所看到的,如果有人可以告诉您Class的用法,我将不胜感激。

有一个内部枚举类型,如何使用?

public static enum Type {

        BETWEEN(2, "IsBetween", "Between"), IS_NOT_NULL(0, "IsNotNull", "NotNull"), IS_NULL(0, "IsNull", "Null"), LESS_THAN(
                "IsLessThan", "LessThan"), LESS_THAN_EQUAL("IsLessThanEqual", "LessThanEqual"), GREATER_THAN("IsGreaterThan",
                "GreaterThan"), GREATER_THAN_EQUAL("IsGreaterThanEqual", "GreaterThanEqual"), BEFORE("IsBefore", "Before"), AFTER(
                "IsAfter", "After"), NOT_LIKE("IsNotLike", "NotLike"), LIKE("IsLike", "Like"), STARTING_WITH("IsStartingWith",
                "StartingWith", "StartsWith"), ENDING_WITH("IsEndingWith", "EndingWith", "EndsWith"), NOT_CONTAINING(
                "IsNotContaining", "NotContaining", "NotContains"), CONTAINING("IsContaining", "Containing", "Contains"), NOT_IN(
                "IsNotIn", "NotIn"), IN("IsIn", "In"), NEAR("IsNear", "Near"), WITHIN("IsWithin", "Within"), REGEX(
                "MatchesRegex", "Matches", "Regex"), EXISTS(0, "Exists"), TRUE(0, "IsTrue", "True"), FALSE(0, "IsFalse",
                "False"), NEGATING_SIMPLE_PROPERTY("IsNot", "Not"), SIMPLE_PROPERTY("Is", "Equals");

        // Need to list them again explicitly as the order is important
        // (esp. for IS_NULL, IS_NOT_NULL)
        private static final List<Part.Type> ALL = Arrays.asList(IS_NOT_NULL, IS_NULL, BETWEEN, LESS_THAN, LESS_THAN_EQUAL,
                GREATER_THAN, GREATER_THAN_EQUAL, BEFORE, AFTER, NOT_LIKE, LIKE, STARTING_WITH, ENDING_WITH, NOT_CONTAINING,
                CONTAINING, NOT_IN, IN, NEAR, WITHIN, REGEX, EXISTS, TRUE, FALSE, NEGATING_SIMPLE_PROPERTY, SIMPLE_PROPERTY);
...}

1 个答案:

答案 0 :(得分:1)

Part在Spring Data内部。客户端代码不打算使用它。因此,如果您不实现自己的Spring Data Modul,则完全不应该使用它,也不应该在其中使用任何东西。

Part基本上是AST的元素,根据使用的商店,很可能会导致where子句或等效元素。

例如如果您有方法findByNameAndDobBetween(String, Date, Date),则解析方法名称将分为两部分。一种用于 name 条件,另一种用于 DOB 条件。

类型枚举列出了可能的所有不同类型的条件。 元素的参数是所需的方法参数数量,以及(可能是多个)String,它们在方法名称中标识此类型。