48 lines
1.6 KiB
Java
Raw Normal View History

2021-07-12 14:51:34 +08:00
package com.xkrs.utils;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
/**
* @author XinYi Song
*/
@Component
public class Query {
/*@Resource
private ProjectOverviewDao projectOverviewDao;*/
/**
* 动态多条件查询项目信息
* @param
* @return
*/
/*public List<ProjectOverview> selectProjectByDynamic(String projectNumber, String projectName) {
Specification<ProjectOverview> specification = new Specification<ProjectOverview>() {
@Override
public Predicate toPredicate(Root<ProjectOverview> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> list = new ArrayList<>();
if (projectNumber != null && !"".equals(projectNumber)) {
list.add(criteriaBuilder.equal(root.get("projectNumber").as(String.class), projectNumber));
}
if (projectName != null && !"".equals(projectName)) {
list.add(criteriaBuilder.like(root.get("projectName").as(String.class), "%" + projectName + "%"));
}
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return projectOverviewDao.findAll(specification);
}*/
}