236.5. 샘플

예를 들어 JMS 대기열에서 빈을 사용하고자 하는 경우 이를 데이터베이스에 삽입하려면 다음을 수행할 수 있습니다.

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

Camel에 호출할 작업 종류를 지시해야 하므로 빈 이름과 메서드 이름을 지정해야 합니다.

여기서 AccountService 는 MyBatis 빈 주석이 있는 빈의 유형 별칭입니다. 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);

}