gpt4 book ai didi

具有两个参数的 Java JPA 查询

转载 作者:行者123 更新时间:2023-12-02 05:13:47 24 4
gpt4 key购买 nike

我正在使用 Java 和 Spring 框架以及 hibernate。我编写了一个接口(interface)来通过查询获取一些库存内容,一个用于位置(库存所在位置),另一个用于产品类型:

    public interface ProductInventory extends Inventory<InventoryItem> {

@Query("select i from InventoryItem i, ProductItem c where i.product = c and c.type = ?1")
List<InventoryItem> findByProductType(ProductItem.ProductItem type);

@Query("select i from InventoryItem i, ProductItem c where i.product = c and c.locationid = ?1")
List<InventoryItem> findByProductLocation(long locationid);
}

这工作完美,但现在我想编写一个选择 ProductType 和位置的查询:

     @Query("select i from InventoryItem i, ProductItem c where i.product = c and c.type = ?1 and c.locationid = ?1")
List<InventoryItem> findByProductStandortAndType(ProductItem.ProductItemType type, long locationid);

但这不起作用。也许有人可以帮助我?非常感谢

最佳答案

那么为什么不在查询中使用第二个参数呢?第一个参数有两次“?1”。

关于具有两个参数的 Java JPA 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27134144/

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