Jpa查询记录
占位符 单参数查询
this.entityManager.createNativeQuery("SELECT statistical_date as statisticalDate, DATE_FORMAT(statistical_date, '%Y') AS year , insured_job_code as insuredJobCode,SUM(policy_daily_total) AS totalPolicy,SUM(policy_daily_price) AS insuFee " + "FROM daily_policy_occupation " + "WHERE customer_id = ? and insu_type = ? and statistical_date >= ? and statistical_date <= ? " + "GROUP BY year,insuredJobCode order by year asc;") .setParameter(1, ao.getCustomerId()) .setParameter(2, ao.getInsuType()) .setParameter(3, ao.getStartDate()) .setParameter(4, ao.getEndDate()) .unwrap(NativeQuery.class) .setResultTransformer(Transformers.aliasToBean(YearlyOccupationInsuFeeVO.class)) .getResultList()
@Query("select new com.compass.dal.model.employer.DailyClaimClosedFeeModel(statisticalDate, sum(closedDailyCount), sum(closedDailyPrice) ,sum(dailyMedicineFee),sum(dailyDeathFee),sum(dailyDisabilityFee),sum(dailyDelayWorkFee),sum(dailyHospitalizationFee),sum(dailyOtherFee)) from DailyClaimFeeTypeDO where customerId = :customerId and statisticalDate >= :startDate and statisticalDate <= :endDate and insuType = :insuType group by statisticalDate order by statisticalDate asc")
List<DailyClaimClosedFeeModel> findByCustomerIdAndInsuTypeAndStatisticalDateBetweenOrderByStatisticalDateAsc(@Param("customerId") String customerId, @Param("insuType") String insuType, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
占位符多参数 指定参数名查询
1 2 3 4 5 6 7 8 9 10 11 | this .entityManager.createNativeQuery( "SELECT statistical_date as statisticalDate, DATE_FORMAT(statistical_date, '%Y') AS year , insured_job_code as insuredJobCode,SUM(policy_daily_total) AS totalPolicy,SUM(policy_daily_price) AS insuFee " + "FROM daily_policy_occupation " + "WHERE customer_id = ? and insu_type = ? and statistical_date >= ? and statistical_date <= ? " + "GROUP BY year,insuredJobCode order by year asc;" ) .setParameter( 1 , ao.getCustomerId()) .setParameter( 2 , ao.getInsuType()) .setParameter( 3 , ao.getStartDate()) .setParameter( 4 , ao.getEndDate()) .unwrap(NativeQuery. class ) .setResultTransformer(Transformers.aliasToBean(YearlyOccupationInsuFeeVO. class )) .getResultList() <br><br> @Query ( "select new com.compass.dal.model.employer.DailyClaimClosedFeeModel(statisticalDate, sum(closedDailyCount), sum(closedDailyPrice) ,sum(dailyMedicineFee),sum(dailyDeathFee),sum(dailyDisabilityFee),sum(dailyDelayWorkFee),sum(dailyHospitalizationFee),sum(dailyOtherFee)) from DailyClaimFeeTypeDO where customerId in (:customerIds) and statisticalDate >= :startDate and statisticalDate <= :endDate and insuType = :insuType group by statisticalDate order by statisticalDate asc" )<br>List<DailyClaimClosedFeeModel> findByCustomerIdsAndInsuTypeAndStatisticalDateBetweenOrderByStatisticalDateAsc( @Param ( "customerIds" ) List<String> customerIds, @Param ( "insuType" ) String insuType, @Param ( "startDate" ) Date startDate, @Param ( "endDate" ) Date endDate); |
本文作者:苍舒
本文链接:https://www.cnblogs.com/cangshublogs/p/14950938.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步