这是一个存储库,我想找到一个集合中menu_id的实体,我想我的函数名称还可以
@Repository
public interface MenuEntityRepository extends JpaRepository<MenuEntity,Long>{
ArrayList<MenuEntity> findByMenuIdIn(List<Long> menuId);
}
但我总是得到错误:
java.lang.IllegalArgumentException: Parameter value element [1] did not match expected type [java.lang.Long (n/a)]
menu_id是@Entity菜单
如长menu_id
但在mysql类型是bigint(20)
所以我把menu_id作为BigInteger列表,所以我得到了错误
好的看起来像ArrayList<MenuEntity>
应该更改为List<MenuEntity>
,因为它不在集合类中arraylist是在抽象集合类中,您需要首先尝试。如果可能有帮助
以下是我的回答
我认为您的findMyMenuIdIn(List<Long> menuId)
不受支持您需要使用您的服务模块进行自己的查询,您无法在存储库中实现这一点,您可以执行findByMenuId (Long menuId)
并使服务模块遍历此查询。
您的方法名称findByMenuIdIn(List<Long> menuid)
确实是正确的并且受支持。我用它,它适合我。但是,您得到的错误与传递给您调用它的方法的参数有关。 java.lang.IllegalArgumentException: Parameter value element [1] did not match expected type [java.lang.Long (n/a)]
建议你的收藏中的第二个项目可能不是Long
类型。检查并确保集合中的所有元素(方法的参数)都是Long
类型。您可能希望发布调用方法的代码段,包括如何在此处创建集合。我希望这有帮助!