您的位置:首页 > 编程语言 > Java开发

MyBatisGenerator的自动生成代码之Eclipse

2017-06-15 21:11 387 查看

下载地址:

https://github.com/mybatis/generator/releases



然后在Eclipse中安装



选择刚刚下载的压缩包,再随便起一个name



Contact allu update...   取消自动更新

再勾选MyBaties Generator 那二项



创建一个简单的项目



配置maven



设置user settings



加载架包Mybatis

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>cn.et</groupId>
<artifactId>Mybatis</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>

<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>

</dependencies>
</project>




加载架包ojdbc

直接build path吧



生成MyBatiesGenerator配置文件

new一个



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>

<!-- api -->
<!--http://mbg.cndocs.tk/-->
<context id="context1">

<!-- 生成根配置文件(jdbc) -->
<jdbcConnection connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" driverClass="oracle.jdbc.OracleDriver" password="tiger" userId="scott" />

<!--
生成emp表的mybatis代码
生成emp的实体类  将表当成类名   列名当成属性名
targetPackage包类
targetProject生成在哪个项目里
-->
<javaModelGenerator targetPackage="cn.et.mabatis.entity" targetProject="Mybatis/src/main/java" />

<!--
生成接口映射的代码  java接口
-->
<sqlMapGenerator targetPackage="cn.et.mabatis.dao" targetProject="Mybatis/src/main/java"
a25c
/>

<!--
生成xml或者注解
targetProject属性
XMLMAPPER 生成xml
ANNOTATEDMAPPER  生成注解

-->
<javaClientGenerator targetPackage="cn.et.mabatis.dao" targetProject="Mybatis/src/main/java" type="XMLMAPPER" />

<!--
选择数据库的表
schema方案 每个用户都有一个唯一的方案,方案名等于用户名
tableName表名
把Example后缀的方法都关闭掉,用不上

-->
<table schema="scott" tableName="emp"  enableCountByExample="false"
enableSelectByExample="false" enableDeleteByExample="false"
enableUpdateByExample="false"
>
</table>
</context>
</generatorConfiguration>




运行配置文件

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: