MyBatisGenerator的自动生成代码之Eclipse

来源:互联网 发布:什么叫it行业 编辑:程序博客网 时间:2024/06/07 01:33

下载地址:

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




然后在Eclipse中安装




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




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

再勾选MyBaties Generator 那二项




创建一个简单的项目




配置maven




设置user settings




加载架包Mybatis

pom.xml

[html] view plain copy
  1. <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">  
  2.   <modelVersion>4.0.0</modelVersion>  
  3.   <groupId>cn.et</groupId>  
  4.   <artifactId>Mybatis</artifactId>  
  5.   <version>0.0.1-SNAPSHOT</version>  
  6.     
  7.   <dependencies>  
  8.       
  9.     <dependency>  
  10.       <groupId>org.mybatis</groupId>  
  11.       <artifactId>mybatis</artifactId>  
  12.       <version>3.2.8</version>  
  13.     </dependency>  
  14.       
  15.   </dependencies>  
  16. </project>  


加载架包ojdbc

直接build path吧




生成MyBatiesGenerator配置文件

new一个




generatorConfig.xml

[html] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">  
  3. <generatorConfiguration>  
  4.   
  5. <!-- api -->  
  6. <!--http://mbg.cndocs.tk/-->  
  7.   <context id="context1">  
  8.       
  9.     <!-- 生成根配置文件(jdbc) -->  
  10.     <jdbcConnection connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" driverClass="oracle.jdbc.OracleDriver" password="tiger" userId="scott" />  
  11.       
  12.     <!--   
  13.         生成emp表的mybatis代码  
  14.         生成emp的实体类  将表当成类名   列名当成属性名  
  15.         targetPackage包类  
  16.         targetProject生成在哪个项目里  
  17.      -->  
  18.     <javaModelGenerator targetPackage="cn.et.mabatis.entity" targetProject="Mybatis/src/main/java" />  
  19.       
  20.     <!--  
  21.         生成接口映射的代码  java接口 
  22.      -->  
  23.     <sqlMapGenerator targetPackage="cn.et.mabatis.dao" targetProject="Mybatis/src/main/java" />  
  24.       
  25.     <!--   
  26.         生成xml或者注解  
  27.         targetProject属性  
  28.         XMLMAPPER 生成xml  
  29.         ANNOTATEDMAPPER  生成注解  
  30.           
  31.      -->  
  32.     <javaClientGenerator targetPackage="cn.et.mabatis.dao" targetProject="Mybatis/src/main/java" type="XMLMAPPER" />  
  33.       
  34.     <!--   
  35.         选择数据库的表  
  36.         schema方案 每个用户都有一个唯一的方案,方案名等于用户名  
  37.         tableName表名  
  38.         把Example后缀的方法都关闭掉,用不上  
  39.           
  40.      -->  
  41.     <table schema="scott" tableName="emp"  enableCountByExample="false"  
  42.     enableSelectByExample="false" enableDeleteByExample="false"  
  43.     enableUpdateByExample="false"  
  44.     >  
  45.     </table>  
  46.   </context>  
  47. </generatorConfiguration>  



运行配置文件


阅读全文
0 0