236.5. 샘플
예를 들어 JMS 큐의 DestinationRule을 사용하여 데이터베이스에 삽입하려는 경우 다음을 수행할 수 있습니다.
from("activemq:queue:newAccount")
.to("mybatis-bean:AccountService:insertBeanAccount");
Provide 이름 및 메서드 이름을 지정해야 합니다. Camel에 어떤 종류의 작업을 호출할지 지시해야 합니다.
여기서 AccountService 는 MyBatisBean 주석이 있는Bean의 유형 별칭입니다. ECDHEMapConfig 파일에서 유형 별칭을 구성할 수 있습니다.
<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);
}