我正在尝试从本机查询中检索值,但如果我将返回的类型作为Object[]
。我收到了类型错误。如果我将其作为BigInteger[]
我只得到一个值。
@Query(value = "select coalesce(sum(individual),0) as individual,
coalesce(sum(groups),0) as groups, coalesce(sum(habitation),0) as habitation, coalesce(sum(works),0) as works,"+
" coalesce(sum(others),0) as others,"+
" coalesce(sum(online),0) as online, coalesce(sum(standalone),0) as standalone, coalesce(sum(excel),0) as excel, coalesce(sum(manual),0) as manual,"+
" coalesce(sum(working),0) as working, coalesce(sum(not_working),0) as not_working, coalesce(sum(under_development),0) as under_development,"+
" coalesce(sum(nic),0) as nic, coalesce(sum(cgg),0) as cgg, coalesce(sum(portal_others),0) as portal_others"+
" from( select dept_id,scheme_id, sub_scheme_id,"+
" case when beneficiary_type = 1 then 1 else 0 end as individual,"+
" case when beneficiary_type = 2 then 1 else 0 end as groups,"+
" case when beneficiary_type = 4 then 1 else 0 end as habitation,"+
" case when beneficiary_type = 5 then 1 else 0 end as works,"+
" case when beneficiary_type = 6 then 1 else 0 end as others,"+
" case when system_type = 1 then 1 else 0 end as online,"+
" case when system_type = 2 then 1 else 0 end as standalone,"+
" case when system_type = 3 then 1 else 0 end as excel,"+
" case when system_type = 4 then 1 else 0 end as manual,"+
" case when system_type = 1 and system_status = 1 then 1 else 0 end as working,"+
" case when system_type = 1 and system_status = 2 then 1 else 0 end as not_working,"+
" case when system_type = 1 and system_status = 3 then 1 else 0 end as under_development,"+
" case when system_type = 1 and software_developed_by = '1' then 1 else 0 end as cgg,"+
" case when system_type = 1 and software_developed_by = '2' then 1 else 0 end as nic,"+
" case when system_type = 1 and (software_developed_by = '0' or software_developed_by = '99') then 1 else 0 end as portal_others"+
" from scheme_details " +
" where is_deleted is false"+
" )t", nativeQuery = true)
public BigInteger[] queryWithCaseValues();
答案 0 :(得分:0)
所以为了检索字段,我必须做很多转换
Object[] schemeDetailValues = (Object[])schemeDetailCount[0];
BigInteger[] retrieveValues = retrieveschemeDetailValues(schemeDetailValues);
adminDashboardCommand.setIndividualBeneficiaryCount(retrieveValues[0].intValue());
adminDashboardCommand.setGroupBeneficiaryCount(retrieveValues[1].intValue());
adminDashboardCommand.setHabitationBeneficiaryCount(retrieveValues[2].intValue());
adminDashboardCommand.setWorksBeneficiaryCount(retrieveValues[3].intValue());
adminDashboardCommand.setOthersBeneficiaryCount(retrieveValues[4].intValue());
adminDashboardCommand.setTotalBeneficiaryCount(retrieveValues[5].intValue());
adminDashboardCommand.setOnlineSystemsAvailableCount(retrieveValues[6].intValue());
adminDashboardCommand.setStandaloneSystemsAvailableCount(retrieveValues[7].intValue());
adminDashboardCommand.setExcelUploadSystemAvailableCount(retrieveValues[8].intValue());
adminDashboardCommand.setManualSystemsAvailableCount(retrieveValues[9].intValue());
adminDashboardCommand.setTotalSystemsAvailableCount(retrieveValues[10].intValue());
adminDashboardCommand.setWorkingSystemsCount(retrieveValues[11].intValue());
adminDashboardCommand.setNonWorkingSystemsCount(retrieveValues[12].intValue());
adminDashboardCommand.setUnderDevelopmentSystemsCount(retrieveValues[13].intValue());
adminDashboardCommand.setNicWebsiteCount(retrieveValues[14].intValue());
adminDashboardCommand.setCggWebsiteCount(retrieveValues[15].intValue());
adminDashboardCommand.setOthersWebsiteCount(retrieveValues[16].intValue());
adminDashboardCommand.setTotalWebsiteCount(retrieveValues[17].intValue());
所以我对Spring Data如何简化开发感到困惑。似乎只有简单的映射才能使用JPA。当归结为本机查询时,它进行了大量的数据转换。当复杂性增加它和使用JDBC一样好时,有人可以告诉我为什么这么多企业会使用它。
谢谢, 的Manoj