Hibernate: select count(employee0_.id) as col_0_0_ from Employee employee0_ where 0=1
高级查询除了为空无法查询出数据,看了Hibernate的底层sql语句有一个where 0=1
后来发现时定制规则的时候出错
原代码
@Overridepublic Specification createSpec() {
return Specifications.< Employee>and().like(StringUtils.isNotBlank(username),"username"+"%"+username+"%").like(StringUtils.isNotBlank(email),"email"+"%"+email+"%").ge(this.age !=null,"age", this.age).build();}
修改后的代码为
@Overridepublic Specification createSpec() {
return Specifications.< Employee>and().like(StringUtils.isNotBlank(username),"username","%"+username+"%").like(StringUtils.isNotBlank(email),"email","%"+email+"%").ge(this.age !=null,"age", this.age).build();}
错误很低级,但这种小错误也是最不容易排查的