【发布时间】:2021-09-01 07:55:18
【问题描述】:
存储库中的代码是
@Query("select divisionName, count(stundeName)FROM StudentDetails GROUP BY divisionName")
public List<Object> getDivisionCount();
服务中的代码是
List <Object> countList= studentDetailsRepository.getDivisionCount();
现在我想遍历 countList 和 categories 然后进入不同的类别,我试过这个
for(int i=0;i< countList.size();i++ )
System.out.println(countList.get(i).getClass().getDeclaredField('count'));
它不工作并给出错误
【问题讨论】:
-
请分享错误,你的代码的objectif是什么!
-
报错就加入吧。
-
为什么返回
Object?它应该是一个带有divisionName和count字段的 POJO(也许您必须在查询中为count(stundeName)起别名。 -
它给出 java.lang.NoSuchFieldException:count
-
@loic 我有 StudentDetails 的 pojo 但是当我使用它作为返回类型时它给了我错误:java.lang.ClassCastException: [Ljava.lang.Object;不能转换为 com.stud.studentSystem.model.StudentDetails
标签: java spring-boot jpa