OR条件查询的问题
opened this issue · comments
// when
Specification specification = Specifications.and()
.eq(isNotBlank(EMPTY), "name", jack.getName())
.like(isNotBlank(EMPTY), "name", "%" + jack.getName() + "%")
.build();
List<Person> persons = personRepository.findAll(specification);
// then
assertThat(persons.size()).isEqualTo(2);
亲,我邮件回复不了你,不支持回复。
你这里是用的 and 条件连接符,我说的是 or 条件连接符哦!
后面我改了,修复了。
测试代码在OrTest.java文件里面。
@Test
public void should_be_able_to_find_all_if_all_predicate_are_null() {
// given
Person jack = new PersonBuilder()
.name("Jack")
.age(18)
.build();
Person eric = new PersonBuilder()
.name("Eric")
.age(20)
.build();
personRepository.save(jack);
personRepository.save(eric);
// when
Specification<Person> specification = Specifications.<Person>or()
.eq(isNotBlank(EMPTY), "name", jack.getName())
.like(isNotBlank(EMPTY), "name", "%" + jack.getName() + "%")
.build();
List<Person> persons = personRepository.findAll(specification);
// then
assertThat(persons.size()).isEqualTo(2);
}
执行的SQL:
select
person0_.id as id1_2_,
person0_.age as age2_2_,
person0_.birthday as birthday3_2_,
person0_.company as company4_2_,
person0_.id_card_id as id_card_7_2_,
person0_.name as name5_2_,
person0_.nick_name as nick_nam6_2_
from
person person0_
https://mvnrepository.com/artifact/com.github.wenhao/jpa-spec
我再maven只看到了3.2之前的版本呢!请问再哪里可以下载最新的版本!谢谢!
我是发布到jcenter的 Gradle的话:
repositories {
jcenter()
}
dependencies {
compile 'com.github.wenhao:jpa-spec:3.2.1'
}
Maven的话估计要等一段时间才会同步过来,你可以直接使用jcenter仓库:
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
好的,非常感谢!