我正在尝试查询findBy。。。在Spring JPA中。它给了我一个java.util.NoSuchElementException
产品类型:
public enum ProductType {
Product, Service, PeriodicalService;
}
控制器:
public ResponseEntity<JsonStruct> findByProductsType(@RequestHeader("MarinaId") Integer idMarina, @PathVariable String[] productTypes){
JsonStruct struct = new JsonStruct();
struct.setStatusToSuccess();
List<ProductType> productTypeList = Arrays.stream(productTypes).map(ProductType::valueOf).collect(Collectors.toList());
struct.put("products", productService.findByProductTypeIn(productTypeList, idMarina));
return new ResponseEntity<JsonStruct>(struct, HttpStatus.OK);
}
ServiceImpl:
@Override
public List<Product> findByProductTypeIn(List<ProductType> productTypes, Integer marinaId){
return productProvider.findByProductTypeIn(productTypes, marinaId);
}
服务:
List<Product> findByProductTypeIn(List<ProductType> productTypes, Integer marinaId);
提供者(这是存储库(:
List<Product> findByProductTypeIn(List<ProductType> productTypes, Integer marinaId);
我看不出我做错了什么。。。
根据spring文档,如果您正在传递集合,那么它将只支持1个参数:
findByProductTypeIn(List<ProductType> productTypes);
如果要使用2个参数,则可能需要对List<ProductType>
&然后使用这样的东西:
findByProductTypeAndMarinaid(ProductType p,Integer marinaid)
如果您的底层数据库支持ProductType
&查询中的Integer
。
您的方法中应该只有一个参数。marinaId应为rénovée以匹配findByProductTypeIn方法。