【发布时间】:2021-12-05 06:38:16
【问题描述】:
下面的代码是我的存储库的一部分。 静态函数不能如下使用,但是我想根据服务接管的参数值接收不同的查询。 你能帮我个忙吗?提前谢谢你。
@Query(value = " select * " +
"from t_user usr " +
"left outer join t_sale_order ord on usr.id = ord.user_idx " +
"LEFT OUTER JOIN ( " +
"SELECT " +
"sale_order_idx, sum(taxable_amount) + sum(non_taxable_amount) as amount " +
"FROM t_sale_receipt " +
"GROUP BY sale_order_idx " +
") receipt " +
"ON receipt.sale_order_idx = ord.id " +
"where NOT exists ( " +
"select 1 from t_encourage_sent_list sl " +
"where sl.user_idx = usr.id and sl.push_idx = ?1 " +
") " +
"AND NOT EXISTS ( SELECT 1 FROM t_user_study us WHERE us.user_idx = usr.id ) " +
// readBookCondition(readBook) +
"AND usr.active = 1", nativeQuery = true)
List<User> findEncouragePushMsgTarget(Integer pushIdx, Integer readBook);
static String readBookCondition(Integer readBook) {
String readBookCondition = "AND NOT EXISTS ( SELECT 1 FROM t_user_study us WHERE us.user_idx = usr.id ) ";
if ( readBook != null ) return "";
if ( readBook != 0 ) readBookCondition.replace("NOT", "");
return readBookCondition;
}
【问题讨论】:
标签: spring-boot jpa dynamicquery nativequery