Skip to content

Commit

Permalink
update BeanHelp.class
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengjie committed Jun 3, 2019
1 parent 18ed58c commit 11b6834
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 32 deletions.
3 changes: 1 addition & 2 deletions eladmin-common/src/main/java/me/zhengjie/utils/BeanHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import me.zhengjie.aop.limit.PredicateInfo;
import me.zhengjie.annotation.PredicateInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,4 @@ public Object queryAll(DictDTO dict){
/** Dong ZhaoYang 2019/6/3 不分页 同理 */
return dictMapper.toDto(dictRepository.findAll((root, query, cb) -> BeanHelp.getPredicate(root, dict, cb)));
}

class Spec implements Specification<Dict> {

private DictDTO dict;

public Spec(DictDTO dict){
this.dict = dict;
}

@Override
public Predicate toPredicate(Root<Dict> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {

List<Predicate> list = new ArrayList<Predicate>();

if(!ObjectUtils.isEmpty(dict.getName())){
/**
* 模糊
*/
list.add(cb.like(root.get("name").as(String.class),"%"+dict.getName()+"%"));
}
if(!ObjectUtils.isEmpty(dict.getRemark())){
/**
* 模糊
*/
list.add(cb.like(root.get("remark").as(String.class),"%"+dict.getRemark()+"%"));
}
Predicate[] p = new Predicate[list.size()];
return cb.and(list.toArray(p));
}
}
}

0 comments on commit 11b6834

Please sign in to comment.