gpt4 book ai didi

java - Iterable 不适用于参数

转载 作者:行者123 更新时间:2023-12-02 01:21:03 25 4
gpt4 key购买 nike

我想为产品类创建一个规范类。它将有一个 Predicate 类来处理 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) -> {})

这是我的类(class):

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;
}

我错过了什么?

最佳答案

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

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

searchCriterias.forEach((criteria) -> {

关于java - Iterable<SearchCriteria> 不适用于参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57663090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com