MyBatisGenerator的自动生成代码之Eclipse

下载地址:

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" />
    
    <!-- 
    	生成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>



运行配置文件









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值