spring data jpa 查询参数为空的问题

tianshenglong tianshenglong 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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的查询条件,哪位知道怎么弄啊!在线等~
...全文
评论 9
收藏 已收藏
分享
返回顶部
tianshenglong
Java EE 67,535 成员 225,843 内容