Mybatis Generator安装及使用
安装
1、下载mybatis-generator-eclipse插件。
2、解压,将features及plugins拷贝到eclipse对应目录下,重启eclipse。
3、file->new,出现MyBatis Generator Configuration File即表明generator安装成功。
使用
1、新建dynamic web project。
2、右键src,new ->source folder,main.resources;右键resources,new->package,com;右键src,new ->source folder,main.java。
3、右键com,new->MyBatis->MyBatis Generator Configuration File。
4、配置generatorConfig.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>
<context id="context1">
<commentGenerator>
<!-- 是否去除自动生成的注释 .true:是 ;false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection connectionURL="jdbc:oracle:thin:@XXX.XXX.XXX.XXX:1521:xxx"
driverClass="oracle.jdbc.driver.OracleDriver" password="xxx"
userId="xxx" />
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.seal.machine.domain"
targetProject="MyBatisGenerator/src/main/java" />
<!-- 生成的映射文件报名和位置 -->
<sqlMapGenerator targetPackage="com.seal.machine.domain"
targetProject="MyBatisGenerator/src/main/java" />
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator targetPackage="com.seal.machine.domain"
targetProject="MyBatisGenerator/src/main/java" type="XMLMAPPER" />
<!-- 要生成的表(更改tableName和domainObjectName即可) -->
<table schema="" tableName="SEAL_MACHINE" domainObjectName="SealMachine"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5、向WEB-INF/lib下添加ojdbc.jar,build path。需要注意的是,oracle12需要使用ojdbc6-xxx.jar。
6、右键generatorConfig.xml,generate MyBatis/IBATIS Artifacts,即可看到生成的文件。
7、将生成的文件拷贝到目标项目,并按需进行修改。