Eclipse + MyBatis Generator Setting(이클립스에 마이바티스 설정)

1. 이클립스에서 Help -> Install New Software...

2. Add... 버튼을 누른 후 이름(사용자 지정)과  MyBatis Plug-in 주소를 입력 한다.

주소 : http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/

3. 아래 스샷과 같이 설치를 진행한다.

4. 설치가 완료 되면 MyBatis Generator을 적용할 웹 프로젝트를 만든다.

5.  DB 연결을 위한 라이브러리(mysql-connector-java-5.1.XX-bin.jar)를 다운로드 하여 해당 프로젝트의 WebContent -> WEB-INF -> lib 폴더에 복사 한다.

※ Mybatis라이브러리도 lib 폴더에 넣어줘야 한다.
Mybatis 라이브러리 다운로드 주소 : http://blog.mybatis.org/p/products.html

라이브러리는 mysql 홈페이지에서 다운로드 가능

다운로드 주소 : http://dev.mysql.com/downloads/connector/j/

6. Eclipse에서 File -> New -> Other -> MyBatis -> MyBatis Generator Configuration File을 선택한다.

7. MyBatis Generator configuration File 을 저장 할 프로젝트와 파일 이름을 설정 한다.

8. Finish 버튼을 눌러 완료 하면 아래 스샷과 같이 프로젝트에 방금 설정한 이름의 xml 파일이 생성 된다.

9. 생성한 xml 파일을 설정에 맞게 수정한다. 
예)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
<classPathEntry location="C:\...\workspace\MyBatisTest\WebContent\WEB-INF\lib\mysql-connector-java-5.1.16-bin.jar" />

<context id="context1">
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://hostname:3306/db" userId="test"
password="xxxxxxxx" />

<javaModelGenerator targetPackage="kr.mybatistest.model"
targetProject="MyBatisTest" />

<sqlMapGenerator targetPackage="kr.mybatistest.xml"
targetProject="MyBatisTest" />

<javaClientGenerator targetPackage="kr.mybatistest.mapper"
targetProject="MyBatisTest" type="XMLMAPPER" />

<table schema="DBName" tableName="tableName1" />
<table schema="DBName" tableName="tableName2" />
<table schema="DBName" tableName="tableName3" />
</context>
</generatorConfiguration>

10. 내용을 맞게 넣었다면 설정 파일(xml)에서 마우스 오른쪽 버튼 클릭 후 "Generate MyBatis/iBATIS Artifacts" 를 선택한다.

11. 위에서 수정된 xml 파일 내용으로 MyBatis Generator에서 패키지와 파일(모델, xml파일, 맵퍼)을 자동으로 생성해 준다.

※ 아래 그림은 테스트로 적용한 화면 이다.