# 条件分组

默认情况下，多个查询条件的关系为“与”，即需要多个条件同时满足。如果需要“或”的逻辑关系（某几个条件只需满足一个即可），只需将多个条件指定为相同的`group`即可。

```java
class Foo {
    Long id;
    int type1;
    int type2;
}
class FooQo {
    @QueryCondition(field="name")
    String name;
    @QueryCondition(group="group1")
    int type1;
    @QueryCondition(group="group1")
    int type2;
}

FooQo fooQo = new FooQo("foo", 1, 2);
Specification<Foo> specification = SpecificationFactory.getSpecification(fooQo);
List<Foo> foos = fooRepository.findAll(specification);
```

生成的SQL：

```sql
SELECT * FROM FOO
WHERE LOWER(FOO.NAME) = 'foo'
	AND (FOO.TYP1 = 1
		OR FOO.TYPE2 = 2);
```

{% hint style="info" %}
group的名字可以任意指定，只需保证相同即可。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ankang.gitbook.io/commons/commons-jpa/gong-neng/tiao-jian-fen-zu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
