【问题标题】:In clause parameters with SPEL带有 SPEL 的子句参数
【发布时间】:2018-02-27 12:02:08
【问题描述】:

我正在尝试使用 Spring-El 传递多个 In Clause 参数,我的查询是:

@Query(nativeQuery = true, value = "select a.* from ACC a where (a.iban, a.currency) in (:#{#ibanAccounts.accountNumber} , :#{#ibanAccounts.currency})")
    List<ACC> getAccount(@Param("ibanAccounts") List<AccountDetails> ibanAccounts);

但我收到以下错误:

EL1008E:(pos 14): Property or field 'accountNumber' cannot be found on object of type 'java.util.ArrayList$SubList' - maybe not public? 
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 14): Property or field 'accountNumber' cannot be found on object of type 'java.util.ArrayList$SubList' - maybe not public?
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:46)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:374)
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131)

在 AccountDetails 中,该字段与公共 getter 一起出现。

谁能指导我怎么了?

【问题讨论】:

  • ibanAccounts 是一个列表,当你说{#ibanAccounts.accountNumber} 框架应该读取哪个 acocuntNumber(of which ibanAccount) 时?
  • @pvpkiran 我想传递列表中所有 ibanAccounts 的所有 accountNumber。可能是我的语法错误。
  • 我相信您正在寻找的是集合投影 docs.spring.io/spring/docs/4.3.12.RELEASE/...。所以你需要使用类似ibanAccounts.![accountNumber]

标签: spring-data spring-data-jpa spring-el


【解决方案1】:

我相信您正在寻找的是collection projection

所以你需要使用这样的东西

@Query(nativeQuery = true, value = "select a.* from ACC a where (a.iban, a.currency) in :#{#ibanAccounts.![accountNumber]} , :#{#ibanAccounts.currency})")
List<ACC> getAccount(@Param("ibanAccounts") List<AccountDetails> ibanAccounts);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多