236.5. サンプル

たとえば、JMS キューから Bean を消費してデータベースに挿入する場合は、次のようにします。

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

呼び出す操作の種類を Camel に指示する必要があるため、Bean 名とメソッド名を指定する必要があることに注意してください。

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);

}