Iterable <SearchCriteria>不适用于参数

时间:2019-08-26 18:30:50

标签: java spring-boot

我想为Product类创建一个规范类。它将具有一个谓词类,该类将处理searchCriterias。

尝试注册searchCriterias时出现错误:

The method forEach(Consumer<? super SearchCriteria>) in the type Iterable<SearchCriteria> is not applicable for the arguments ((<no type> key, <no type> criteria) -> {})

这是我的课程:

public class ProductSpecifications implements Specification<Product>{

    // List of search criterias to be applied to 
    private final List<SearchCriteria> searchCriterias;

    public ProductSpecifications() {
        searchCriterias = new ArrayList<SearchCriteria>();
    }

    @Override
    public Predicate toPredicate(Root<Product> root, CriteriaQuery<?> query, CriteriaBuilder builder) {

        searchCriterias.forEach((key, criteria) -> {
        if (criteria.getOperation().equalsIgnoreCase(">")) {
            return builder.greaterThanOrEqualTo(
            root.<String> get(criteria.getKey()), criteria.getValue().toString());
        } 
        ....

这是我的搜索条件课程:

public class SearchCriteria {
    private String key;
    private String operation;
    private Object value;
}

我想念什么?

1 个答案:

答案 0 :(得分:2)

您正在尝试将List迭代为Map。你必须改变

searchCriterias.forEach((key, criteria) -> {

searchCriterias.forEach((criteria) -> {