Skip to content

Field Parameters

Field parameters are a series of parameters derived from the conditional attributes that have database field mappings in the retrieval entity class. They play a role in filtering the query results.

Conditional attributes include two types: [field attributes](/en/guide/bean/fields.html#Field Attributes) and [additional attributes](/en/guide/bean/fields.html#Additional Attributes - Since v4.1.0); For whether the field parameters specifically generate a where condition or a having condition, please refer to the [Conditional Attributes > Where or Having](/en/guide/bean/fields.html#Where or Having) section.

Derived Field Parameters

Derivation Rules

For example, for the following entity class:

java
public class User {
    private String name;
    // Omit other..
}

Taking its name field as an example, the following series of field parameters can be derived:

  • name-{n}: The nth parameter value of the name field, such as name-0, name-1, name-2, etc. (If you can't understand, [refer here](/en/guide/start/use#_11-Field Filtering - field-op-bt))
  • name: Equivalent to name-0, the 0th parameter value of the name field
  • name-op: The [field operator](#Field Operators) of name, such as Equal, GreaterEqual, GreaterThan, etc.
  • name-ic: Whether the case should be ignored when retrieving the name field

When deriving field parameters above, the hyphen (-) is used as a connector. If you prefer the underscore (_), you can configure bean-searcher.params.separator to the underscore. After configuring it to the underscore, the derived parameters will be name_{n}, name, name_op, name_ic. Similarly, you can also customize the op and ic suffixes.

TIP

Field parameters are derived from the JAVA field names (not table fields) in the entity class and are decoupled from the database table fields.

Configurable Items

In a SpringBoot / Grails project, if the bean-searcher-boot-starter dependency is used, you can customize the field parameters through the following configuration items in the application.properties or application.yml file of the project:

Configuration Key NameMeaningOptional ValuesDefault Value
bean-searcher.params.separatorSeparator for field parameter namesString-
bean-searcher.params.operator-keySuffix for the field operator parameter nameStringop
bean-searcher.params.ignore-case-keySuffix for the field parameter name indicating whether to ignore caseStringic

Extended Derived Parameters

In addition, if you find the default derived field parameters not very useful, you can use the [parameter filter](/en/guide/advance/filter#Parameter Filter) to customize new rules. In fact, since v4.3.0, Bean Searcher has come with some filters for simplifying derived parameters:

Field Operators

Field operators are used to describe the retrieval method of a certain field, that is, the SQL splicing method. Bean Searcher provides a total of 22 different field operators by default, as shown in the following table:

The meaning of Ignore empty values in the following table is: if the parameter value of this field is null or an empty string, whether to ignore this condition.

OperatorAbbreviationSQL SnippetWhether to Ignore Empty ValuesMeaning
Equaleqx = ?YesEqual to (the default operator)
NotEqualnex != ?YesNot equal to
GreaterThangtx > ?YesGreater than
GreaterEqualgex >= ?YesGreater than or equal to
LessThanltx < ?YesLess than
LessEquallex <= ?YesLess than or equal to
Betweenbtx between ?1 and ?2 / x >= ?1 / x <= ?2YesBetween... (range query)
NotBetweennbx not between ?1 and ?2 / x < ?1 / x > ?2YesNot between... (range query) (since v3.3)
Containctx like '%?%'YesContain (fuzzy query) (since v3.2)
StartWithswx like '?%'YesStart with... (fuzzy query)
EndWithewx like '%?'YesEnd with... (fuzzy query)
OrLikeolx like ?1 or x like ?2 or ...YesFuzzy or match (can have multiple parameter values) (since v3.7)
NotLikenkx not like ?YesAnti-fuzzy match (since v3.8)
InListilx in (?, ?, ...)YesMulti-value query (New since v3.3, previously MultiValue / mv)
NotInnix not in (?, ?, ...)YesMulti-value query (since v3.3)
IsNullnlx is nullNoIs null (since v3.3)
NotNullnnx is not nullNoIs not null (since v3.3)
Emptyeyx is null or x = ''NoIs empty (only applicable to fields of string type)
NotEmptynyx is not null and x != ''NoIs not empty (only applicable to fields of string type)
AlwaysTrueat1NoAlways true (since v4.3)
AlwaysFalseaf0NoAlways false (since v4.3)
SqlCondsqlCustom SQL conditionNoCan only be used in the parameter builder. Refer to the Custom SQL Condition section (since v3.8.0)

In addition

You can also customize operators. Refer to the Advanced > Mastering Operators section.

Since Bean Searcher provides full names and abbreviations for operators, there are several equivalent usages for each operator.

For example, to query users whose name is equal to Jack:

  • Backend parameter construction:
java
Map<String, Object> params = MapUtils.builder()
        .field("name", "Jack")          // (1) The value of the field `name` is Jack
        .field(User::getName, "Jack")   // Equivalent to (1) 
        .op("eq")                       // (2) Specify the operator of the `name` field as `eq` (the default is `eq`, so it can also be omitted)
        .op("Equal")                    // Equivalent to (2) 
        .op(FieldOps.Equal)             // Equivalent to (2) 
        .op(Equal.class)                // Equivalent to (2) 
        .build();
User jack = searcher.searchFirst(User.class, params);           // Execute the query
  • Front-end parameter passing form:
js
GET /users ? name=Jack & name-op=eq        // (1) The value of the field `name` is Jack, and the operator is `eq`
GET /users ? name=Jack & name-op=Equal     // Equivalent to (1) 
GET /users ? name-0=Jack & name-op=eq      // Equivalent to (1) 
GET /users ? name-0=Jack & name-op=Equal   // Equivalent to (1) 
GET /users ? name=Jack          // (2) When there is no operator constraint for `name`, or the first operator constraint is `Equal`, it is equivalent to (1) 
GET /users ? name-0=Jack        // Equivalent to (2)

Released under the Apache License