camel mybatis组件只支持列表参数,必须命名为'list'?

时间:2017-11-20 02:41:29

标签: java apache-camel mybatis

当我在项目中使用camel-mybatis组件时,我发现list参数必须命名为'list'

以下示例有效:

from(xxx)
   ...
   ...
   .setHeader("list",simple("${body.OriginCodeList}"))
   .to("mybatis:selectByInnerCodeList?statementType=SelectList&inputHeader=list")

mybatis mapper xml:

<select id="selectByInnerCodeList" resultMap="BaseResultMap" parameterType="java.util.List">
    select
    <include refid="Base_Column_List" />
    from MF_FundManagerNew
    WHERE Incumbent=1
    <if test="list!=null and list.size()>0 ">
      and InnerCode IN
      <foreach collection="list" item="innerCodeSingle" open="(" close=")" separator=",">
        #{innerCodeSingle}
      </foreach>
    </if>
</select>

成功

此路线失败

from(xxx)
  ...
  ...
  .setHeader("innerCodeList",simple("${body.OriginCodeList}"))
  .to("mybatis:selectByInnerCodeList?statementType=SelectList&inputHeader=innerCodeList")

mybatis mapper xml:

<select id="selectByInnerCodeList" resultMap="BaseResultMap" parameterType="java.util.List">
    select
    <include refid="Base_Column_List" />
    from MF_FundManagerNew
    WHERE Incumbent=1
    <if test="innerCodeList!=null and innerCodeList.size()>0 ">
      and InnerCode IN
      <foreach collection="innerCodeList" item="innerCodeSingle" open="(" close=")" separator=",">
        #{innerCodeSingle}
      </foreach>
    </if>
</select>

第二个示例抛出以下异常:

Error querying database.  Cause: org.apache.ibatis.binding.BindingException: 
Parameter 'innerCodeList' not found. Available parameters are [collection, list]
Cause: org.apache.ibatis.binding.BindingException: Parameter 'innerCodeList' not found. Available parameters are [collection, list]
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.4.1.jar:3.4.1]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150) ~[mybatis-3.4.1.jar:3.4.1]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) ~[mybatis-3.4.1.jar:3.4.1]
at org.apache.camel.component.mybatis.MyBatisProducer.doSelectList(MyBatisProducer.java:117) ~[camel-mybatis-2.20.0.jar:2.20.0]
at org.apache.camel.component.mybatis.MyBatisProducer.process(MyBatisProducer.java:63) ~[camel-mybatis-2.20.0.jar:2.20.0]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.FilterProcessor.process(FilterProcessor.java:57) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.component.mybatis.MyBatisConsumer.processBatch(MyBatisConsumer.java:130) [camel-mybatis-2.20.0.jar:2.20.0]
at org.apache.camel.component.mybatis.MyBatisConsumer.poll(MyBatisConsumer.java:100) [camel-mybatis-2.20.0.jar:2.20.0]
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174) [camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101) [camel-core-2.20.0.jar:2.20.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_144]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_144]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_144]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]

1 个答案:

答案 0 :(得分:1)

让我在这里把我的评论作为答案:

在MyBatis中,如果您直接绑定Collection对象,那么它将在MyBatis XML中作为collectionlist变量提供,因为它默认为该名称。

如果您需要使用其他密钥,则可以将其包装在具有属性innerCodeList的对象中,或者将其放在Map中,密钥为innerCodeList。在这种情况下,parameterType的{​​{1}}将为<select>YourCustomClass