236.5. Samples

例如,如果您想要使用 JMS 队列中的 Bean,并将其插入到数据库中:

from("activemq:queue:newAccount")
  .to("mybatis-bean:AccountService:insertBeanAccount");

请注意,我们必须指定 bean 名称和方法名称,因为我们需要指示 Camel 要调用的操作。

其中 AccountService 是带有 MyBatis bean 注解的 bean 类型别名。您可以在 SqlMapConfig 文件中配置类型别名:

    <typeAliases>
        <typeAlias alias="Account" type="org.apache.camel.component.mybatis.Account"/>
        <typeAlias alias="AccountService" type="org.apache.camel.component.mybatis.bean.AccountService"/>
    </typeAliases>
On the `AccountService` bean you can declare the MyBatis mappins using annotations as shown:
public interface AccountService {

    @Select("select ACC_ID as id, ACC_FIRST_NAME as firstName, ACC_LAST_NAME as lastName"
        + ", ACC_EMAIL as emailAddress from ACCOUNT where ACC_ID = #{id}")
    Account selectBeanAccountById(@Param("id") int no);

    @Select("select * from ACCOUNT order by ACC_ID")
    @ResultMap("Account.AccountResult")
    List<Account> selectBeanAllAccounts();

    @Insert("insert into ACCOUNT (ACC_ID,ACC_FIRST_NAME,ACC_LAST_NAME,ACC_EMAIL)"
        + " values (#{id}, #{firstName}, #{lastName}, #{emailAddress})")
    void insertBeanAccount(Account account);

}