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 中国大陆许可协议进行许可。

posted @   苍舒  阅读(92)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起