如何为myBatis组件提供所需的查询参数?我想通过id选择一个简单的Select语句。最好的解决方案是直接从Cxf有效载荷中自动提取参数。
我没有为myBatis映射使用任何域类。 使用getAll方法时,Route可以正常工作。
到目前为止,我的路线看起来像这样:
@Override
public void configure() throws Exception {
from(cxfEndpoint).to("mybatis:getById?statementType=SelectList")
});
和我的映射器配置:
<?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>
答案 0 :(得分:2)
您应该使用Id本身填充您的身体。它可以只是Integer类型的对象:
from(cxfEndpoint).setBody(Integer.valueOf(123)).to("mybatis:getById?statementType=SelectList")
其中123是你的想法。
答案 1 :(得分:2)
您可以使用inputHeader参数设置标题并将其传递给mybatis。
示例:
from(cxfEndpoint)
.setHeader("myHeader").simple("some value")
.to("mybatis:getById?statementType=SelectList?inputHeader=myHeader")