public interface PosAccountRecordRepository extends JpaRepository<PosAccountRecord, String> { List<PosAccountRecord> findTop3ByposAccountIdAndRecordTypeOrderByRecordTimeDesc(final String posAccountId, final int recordType); @Query(value="SELECT " + "SUM(pos.AMOUNT) sumamount, COUNT(1) sumcount, pos.RECORD_TYPE FROM " + "POS_ACCOUNT_RECORD pos " + "GROUP BY pos.RECORD_TYPE ",nativeQuery=true) List<Object[]> findPosAccountCollect(); @Query(value="SELECT " + "SUM( IF ( pos.RECORD_TYPE = 0, pos.AMOUNT,0 ) ) AS sumincomeamount, " + "SUM( IF ( pos.RECORD_TYPE = 1, pos.AMOUNT,0 ) ) AS sumoutgoamount, " + "SUM( IF ( pos.RECORD_TYPE = 0, 1,0 ) ) AS sumincomecount, " + "SUM( IF ( pos.RECORD_TYPE = 1, 1,0 ) ) AS sumoutgocount " + "FROM POS_ACCOUNT_RECORD pos " + "where 1=1 " + "and pos.RECORD_TIME <= STR_TO_DATE(:a,"%Y-%m-%d") ",nativeQuery=true) List<Object[]> findPosAccountSumCollect(@Param(value = "a") String a); }
代码如上,在执行 上述的 findPosAccountSumCollect 方法时,假如参数a为空,就不执行 where中 带参数a的查询条件,哪位知道怎么弄啊!在线等~
解决方案