如何处理jdbc出站查询参数中的空格?

时间:2018-05-14 07:40:42

标签: xml spring spring-integration

我不知道这是否与集成相关,但在我的上下文中,我尝试通过包含空格的键引用有效负载值:

<int-jdbc:outbound-channel-adapter 
    query="INSERT INTO table (serial, dealer_code) VALUES (:payload[SERIES], :payload[DEALER CODE])"
    data-source="dbDataSource">

</int-jdbc:outbound-channel-adapter>

虽然:payload[SERIES]参数有效,但只要我添加第二个参数:

  • :payload[DEALER CODE]
  • :payload['DEALER CODE']
  • :payload[&quot;DEALER CODE&quot;]

工作,而且最后两次打破了:

org.springframework.dao.InvalidDataAccessApiUsageException: No value supplied for the SQL parameter 'payload[': Invalid property 'payload[' of bean class [org.springframework.messaging.support.GenericMessage]: Bean property 'payload[' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

在其他地方,在另一个enpoint配置中我使用引号:

<int-http:inbound-channel-adapter id="/api/requests"
    ...
    status-code-expression="T(org.springframework.web.context.request.RequestContextHolder).requestAttributes.request.method.equals('POST') ? 201 : 200">

</int-http:inbound-channel-adapter>

我已经解决了这个问题,添加了ExpressionEvaluatingSqlParameterSourceFactory(如Inbound Channel Adapter中所述):

<int-jdbc:outbound-channel-adapter 
    query="INSERT INTO table (serial, dealer_code) VALUES (:serial, :dealerCode)"
    sql-parameter-source-factory="spelSource"
    data-source="dbDataSource">

</int-jdbc:outbound-channel-adapter>

<bean id="spelSource"
  class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
    <property name="parameterExpressions">
        <map>
            <entry key="serial" value="payload['SERIES']"/>
            <entry key="dealerCode" value="payload['DEALER CODE']"/>
        </map>
    </property>
</bean>

</int-jdbc:outbound-channel-adapter>

但由于只读取了有效载荷字段,这似乎太多了。

我在这里使用了错误的语法吗?

1 个答案:

答案 0 :(得分:1)

尝试将ExpressionEvaluatingSqlParameterSourceFactory用于sql-parameter-source-factory的{​​{1}}属性。确实,表达必须是这样的:<int-jdbc:outbound-channel-adapter >