findByAnd 不兼容的类型
findByAnd incompatible types
我正在尝试使用方法 findByAnd。
这是我的部分代码:
ArrayList<String> orderBy;
orderBy.add("productId");
GenericDelegator delegator = (GenericDelegator) DelegatorFactory.getDelegator("default");
GenericValue product = null;
try {
product = delegator.findByAnd("Product", UtilMisc.toMap("productName", productName), orderBy, false);
} catch (GenericEntityException e) {
return Response.serverError().entity(e.toString()).build();
}
这一行
product = delegator.findByAnd("Product", UtilMisc.toMap("productName", productName), orderBy, false);
我收到这个错误:
如何纠正?我不明白类型如何在我的代码中不兼容。
您收到此错误的原因是因为 findByAnd 方法 returns 一个 GenericValue 对象列表,每个 GenericValue 代表 Product table 中的一行。
以下代码将起作用:
List<GenericValue> products = delegator.findByAnd("Product", UtilMisc.toMap("productName", productName), orderBy, false);
我正在尝试使用方法 findByAnd。
这是我的部分代码:
ArrayList<String> orderBy;
orderBy.add("productId");
GenericDelegator delegator = (GenericDelegator) DelegatorFactory.getDelegator("default");
GenericValue product = null;
try {
product = delegator.findByAnd("Product", UtilMisc.toMap("productName", productName), orderBy, false);
} catch (GenericEntityException e) {
return Response.serverError().entity(e.toString()).build();
}
这一行
product = delegator.findByAnd("Product", UtilMisc.toMap("productName", productName), orderBy, false);
我收到这个错误:
如何纠正?我不明白类型如何在我的代码中不兼容。
您收到此错误的原因是因为 findByAnd 方法 returns 一个 GenericValue 对象列表,每个 GenericValue 代表 Product table 中的一行。 以下代码将起作用:
List<GenericValue> products = delegator.findByAnd("Product", UtilMisc.toMap("productName", productName), orderBy, false);