> For the complete documentation index, see [llms.txt](https://ankang.gitbook.io/commons/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ankang.gitbook.io/commons/commons-jpa/gong-neng/gong-neng-2.md).

# 简单查询

当查询对象中所有的查询条件匹配方式均为“相等”，并且字段名和实体中的字段名相同时，只需要在作为查询条件的字段上增加`@QueryCondition`即可。

```java
class Foo {
    Long id;
    String name;
    String content;
}
class FooQo {
    @QueryCondition
    Long id;
    @QueryCondition
    String name;
    String content; // 不加注解，不作为查询条件
}

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

生成的SQL：

```sql
SELECT DISTINCT *
FROM FOO
WHERE FOO.ID = 1
	AND LOWER(FOO.NAME) = 'foo';
```

{% hint style="info" %}
字符串条件默认会忽略大小写
{% endhint %}

如果查询对象中的所有字段均作为查询条件，可以在查询对象上声明`@QueryObject`注解，相当于在所有字段上声明`@QueryCondition`注解。

```java
class Foo {
    Long id;
    String name;
    String content;
}
@QueryObject
class FooQo {
    Long id;
    String name;
    String content;
}

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

生成的SQL：

```sql
SELECT * FROM FOO
WHERE FOO.ID = 1
	AND LOWER(FOO.NAME) = 'foo'
	AND LOWER(FOO.CONTENT) = 'content';
```
