質問

How can I provide myBatis component with desired query parameters? I want to perfom a simple Select statement with selection by id. The best solution would be a possibility of having automatic parameter extraction directly from Cxf payload.

I'm not using any domain classes for myBatis mapping. Route works fine when using getAll method.

So far, my route looks like this:

@Override
public void configure() throws Exception {
    from(cxfEndpoint).to("mybatis:getById?statementType=SelectList")
    });

and my mapper configuration:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="User">

  <select id="getAll" resultType="map">
      SELECT * FROM USERS
  </select>

  <select id="getById" parameterType="int" resultType="map">
      SELECT * FROM USERS WHERE ID = #{id}
  </select>

</mapper>
役に立ちましたか?

解決

You should just populate your body with the Id itself. It can be just an object of type Integer:

from(cxfEndpoint).setBody(Integer.valueOf(123)).to("mybatis:getById?statementType=SelectList")

where 123 is your Ide.

他のヒント

You can set a header and pass it to mybatis using inputHeader parameter.

Example:

from(cxfEndpoint)
  .setHeader("myHeader").simple("some value")
  .to("mybatis:getById?statementType=SelectList?inputHeader=myHeader")
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top