【发布时间】:2020-10-10 14:42:07
【问题描述】:
我有一个包含 10000 条记录的对象列表,我试图将这些记录拆分为 10 条记录,
但不知何故它不起作用..有人可以看看
@Query("select a.applicantid,coalesce(to_char(a.createdon,'yyyy-MM-dd'),to_char(filing_date,'yyyy-MM-dd')) as dt1, \r\n" +
"coalesce(c.companyname,i.InstituteName,(u.firstname||' '||u.lastname),\r\n" +
"u.firstname) ,a.c_denomination,cc.crop_common_name,cs.crop_botanical_name,\r\n" +
"a.id,aps.status,a.cropid, \r\n" +
"(select mv.varietytype from VarietyType mv where mv.id= a.varirtytypeid),\r\n" +
"(select sv.subvarietytype from SubVarietyType sv,VarietyType mvr \r\n" +
" where a.subvarietytypeid = sv.id and mvr.id= sv.varietyid),a.formtype,mcg.crop_group \r\n" +
" from Applications a left join ApplicantRegistration ap on \r\n" +
" a.applicantid = ap.id left join CompanyRegistration c on ap.companyid = c.id \r\n" +
" left join InstitutionRegistration i on ap.institutionid = i.id \r\n" +
" left join Crops cc on a.cropid = cc.id left join CropSpecies cs \r\n" +
" on a.cropspeciesid =cs.id left join InternalUser u on ap.id = u.applicantid \r\n" +
" left join ApplicationStatus aps on a.application_current_status = aps.id "
+ "left join CropGroup mcg on cc.cropgroupid = mcg.id order by a.id desc")
List<Object[]> getapplication_adminview();
List<Object[]> admin_viewapplication=applicationrepository.getapplication_adminview();
int pageNumber = 0;
int size = 10;
Pageable pageable = PageRequest.of(pageNumber, size); // object of pageable
Page<Object> pages = new PageImpl(admin_viewapplication, pageable, admin_viewapplication.size());
List<Object> lpage = pages.getContent(); // here i am getting the lpage size as 10000 but as i enter pageable as of size 10 i am expecting 10 results only
我在哪里出错了? 如果我尝试添加可分页对象来查询和运行代码,我将收到以下错误:
无法使用请求的结果类型 [java.lang.Long] 为具有多个返回的查询创建 TypedQuery;嵌套异常是 java.lang.IllegalArgumentException:无法使用请求的结果类型 [java.lang.Long] 为具有多个返回的查询创建 TypedQuery
【问题讨论】:
-
你能显示你的存储库方法
getapplication_adminview吗? -
@Eklavya 已更新 ...如果我尝试将 pagable 添加到存储库方法,则会给出错误,即它是 typedquery..
-
如果不使用分页,您的数据是否正确获取?您是否收到任何错误,请附上它们。
-
请附上您在存储库方法中添加分页时遇到的错误
-
@Eklavya 看到我之前尝试过使用 pageable ,我们所做的基本工作是获取结果并使用 findall() 方法添加 Pageable ......但是这里的查询是从许多人那里获取结果列..这里它不起作用...
标签: spring-boot jpa pageable